Module 11 of 15 · Step 1 of 14

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
Concept 1 of 5

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

  1. word[0] reads the first character P.
  2. len(word) counts six characters.
  3. The quotes define text but are not counted as characters.

Common mistake

Not this
word[1]  # expecting P
Try this
word[0]

String positions begin at zero, just like list positions.