Strings
A string is text.
Letters, words, emoji, and spaces can live in a string.
Think of a string as beads on a thread. Each bead is one character.
You make a string with quotes.
Making strings
Use single quotes or double quotes.
Both are fine. Stay consistent in one file.
Joining strings
Use + to stick strings together.
Like taping two paper strips into one longer strip.
If you need a space, put the space in yourself.
Repeating and length
A star with a number repeats the text.
len() counts the characters.
Indexing characters
Each character has a place number.
Counting starts at 0.
Negative numbers count from the end.
Slicing a piece
A slice takes a part of the string.
Write [start:end]. The end place is not included.
word[0:2] takes the first two characters
word[:3] starts at the beginning
word[2:] goes to the end
word[:] copies the whole string
f-strings for filling blanks
An f-string lets you drop variables into text.
Put f before the quotes. Put names in curly braces.
Tip: Strings do not change in place. Methods make new strings. We cover methods next.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.