All lessons

Strings & booleans · step 5 of 22

What is a string?

8 minText, length, joining and the f-strings you will use every day.

Strings are sequences of characters

A string is text: any collection of characters between quotes. A space counts as a character too.

greeting = "Hello"
print(greeting + " there")   # joining strings is called concatenation
print(len(greeting))         # 5

Building sentences with f-strings

An f-string lets you drop values straight into a sentence: put an f before the quotes and wrap each value in braces.

name = "Ada"
age = 36
print(f"{name} is {age} years old")

f-strings are the readable, modern way to build text — reach for them instead of gluing pieces together with +.

Strings are not numbers

"5" + "5" gives "55", because Python joins two pieces of text. Convert with int("5") or float("5.5") when you need a number.

Remember this

  • A string is text between quotes
  • f-strings put values inside a sentence
  • Numbers in quotes are still text — convert with int() or float()

Quick quiz

Three questions. 3 correct answers and you have the idea — you can retry as often as you like.

  1. 1. What does len("Hello!") give?

  2. 2. Which line prints `Ada is 36`?

  3. 3. What is "3" + "4"?

Answer all three to check them.

Now write it yourself

0/3 passed
1

Practice 1

Two variables are ready for you: `first` and `last`. Print the full name with a single space between them.

practice_1.py

Given for you

first = "Ada"
last = "Lovelace"
2

Practice 2

The variables `a = 3` and `b = 4` are ready. Use an f-string to print exactly: 3 + 4 = 7

practice_2.py

Given for you

a = 3
b = 4
3

Practice 3

The price is stored as text: `price = "19.99"`. Print the price plus 5.01 so the output is 25.0

practice_3.py

Given for you

price = "19.99"

Finish with two of three quiz answers correct and every exercise passing, and this lesson is marked complete.