Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Strings · Lesson 9 of 11

Strings

A free lesson from Swipe Coding · Python, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Strings are probably the building block you'll type most — worth learning their tricks well. 🐍

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 TypeError
+ joins two strings together, but it cannot mix a string with a number directly.

The 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}.")
f-strings insert variable values directly into the text, with no manual conversion or + needed.
🤖
Slicing trips people up at first — that 'up to but not including' part is the whole trick. ✂️

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
len(), .upper(), .lower(), and slicing are some of the most frequently used string tools.
Fill in the blank

To insert a variable directly into a string without manually converting it, you can write an ____, such as f"Hello, {name}".

Quick check

What does "Python"[0:3] return?

True or false

In Python, "hello" + 5 works fine and automatically converts the number to text.

Chapter quiz

Strings

10 questions · pass with 60% — just like in the app.

True or false

In Python, single quotes and double quotes both create the same kind of string.

Quick check

What happens when you try to write "Score: " + 95 in Python?

Fill in the blank

Writing f"Hello, {name}" is an example of an ____.

Quick check

What does len("Python") return?

True or false

String indexing and slicing in Python start counting at 0.

Fill in the blank

"Python"[0:3] returns ____.

Quick check

Which method returns a new string with all letters converted to uppercase?

True or false

f-strings automatically convert the values inside {} to text for you.

Fill in the blank

The ____ operator joins two strings together, such as "Py" + "thon".

Quick check

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 →