Courses/Python Basics

๐Ÿ Python Basics

Working with Strings

Slice, format, and transform text.

Strings are sequences of characters. You can index them with [i], slice with [a:b], and call methods on them.

s = "Python"
print(s[0])       # P
print(s[-1])      # n
print(s[1:4])     # yth
print(s.upper())  # PYTHON

f-strings let you embed expressions directly: f"length = {len(s)}".

main.py
Output
Press Run to execute.
Expected output
PYTHON
It has 6 letters.

Sign in to track your progress across lessons.