Strings
A string is text. You can read its characters, measure its length, clean it, replace parts, and build a message from values.
By the end of this lesson, you can:
- Read characters and length
- Use common text methods
- Check membership and join strings
- Build messages with f-strings
Strings lesson progress0%
Course progress: 0% · 0 of 14 steps completed in this module
Learn · Text is a sequence of characters
Text is a sequence of characters
Put text inside matching single or double quotes. Each character has an index starting at 0. The last character can be read with -1; len() counts the characters.
Pattern
word[0]
word[-1]
len(word)Code
word = "Python"
print(word[0])
print(len(word))Output
P 6
Why it works
- word[0] reads the first character P.
- len(word) counts six characters.
- The quotes define text but are not counted as characters.
Common mistake
Not this
word[1] # expecting PTry this
word[0]String positions begin at zero, just like list positions.