Strings
A free lesson from Swipe Coding · Python, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
A string is a piece of text, and Python is flexible about how you write one: you can use single quotes ('hello') or double quotes ("hello") interchangeably — both create the exact same kind of string. It's useful to know both work, especially when your text itself contains a quote character, like 'She said "hi"'. You can join strings together with the + operator, called concatenation — though unlike some languages, Python will not automatically convert a number to text for you with +, so mixing a string and a number this way causes an error.
first = "Py"
second = "thon"
print(first + second) # PyThon
# print("Score: " + 95) # this would raise a TypeErrorThe much more convenient way to build text with variables inside it is an f-string: put an f right before the opening quote, then write any expression inside curly braces {} and Python inserts its value automatically, converting it to text for you.
name = "Ada"
points = 95
print(f"Hello, {name}! Your score is {points}.")Strings come with useful tools. len(s) returns how many characters are in a string. .upper() and .lower() return a new copy of the string in all uppercase or all lowercase. Slicing, written s[start:end], grabs a piece of the string from index start up to (but not including) index end — and like everything in Python, indexing starts counting at 0.
word = "Python" print(len(word)) # 6 print(word.upper()) # PYTHON print(word.lower()) # python print(word[0:3]) # Pyt
To insert a variable directly into a string without manually converting it, you can write an ____, such as f"Hello, {name}".
What does "Python"[0:3] return?
In Python, "hello" + 5 works fine and automatically converts the number to text.
Strings
10 questions · pass with 60% — just like in the app.
In Python, single quotes and double quotes both create the same kind of string.
What happens when you try to write "Score: " + 95 in Python?
Writing f"Hello, {name}" is an example of an ____.
What does len("Python") return?
String indexing and slicing in Python start counting at 0.
"Python"[0:3] returns ____.
Which method returns a new string with all letters converted to uppercase?
f-strings automatically convert the values inside {} to text for you.
The ____ operator joins two strings together, such as "Py" + "thon".
Why does "hello" + 5 raise an error in Python?
Keep your streak going in Swipe Coding
Swipe through every level of Python on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →