Strings · Lesson 5 of 25
Strings and f-strings
Put variables inside text, plus handy string tools.
6 minutes3 games
An f-string: put f before the quote and write variables inside { } in the text. The clearest way to build text.
Python
name = "Karim"
score = 92
print(f"{name} scored {score} points")
print(f"Next goal: {score + 5}")
word = "seacode"
print(word.upper(), len(word), word[0], word[-1])| Tool | Use |
|---|---|
| Character count |
| First character |
| Format a number to two decimal places |
Python
price = 12.5
qty = 3
print(f"Total: {price * qty:.2f} EGP")Complete the code
Complete the f-string so it prints Hi Laila.
user = "Laila" print("Hi {}")
What's the output?
print(len("Cairo"))What will this code print?
Exercise
Print Total: 150 EGP with an f-string from the two variables.
Expected output: Total: 150 EGP
Python
price = 50 qty = 3
Learn more from
Played 0 of 3 games
Sign in to save your progress and earn XP.