Concept
f-strings (f"{var}")
Legacy formatting is dead. Modern Python uses formatted string literals: **f-strings**. Stick an `f` before the opening quote, and drop variables directly inside curly brackets `{}`:
python
user = "Neo"
score = 9999
print(f"Player {user} has {score} points!")# 41. f-strings (f"{var}") Legacy formatting is dead. Modern Python uses formatted string literals: **f-strings**. Stick an `f` before the opening quote, and drop variables directly inside curly brackets `{}`: ```python user = "Neo" score = 9999 print(f"Player {user} has {score} points!") ``` Python injects them instantly, automatically converting numbers to text behind the scenes without calling `str()`.
Checkpoint
Why do developers prefer `f"Score: {points}"` over `"Score: " + str(points)`?
Practice
You have `name = "Ada"` and `level = 10`. Use an f-string to print `"Ada reached level 10!"`.
01
Tap code blocks below to assemble
Available Blocks