f-strings: drop values right into your text
An f-string lets you build a sentence with your values tucked right inside it. Put an f before the quotes, then drop names into { }.
The big idea
An f-string is text with values slotted in using { }.
See it in code
Put an f before the quotes, then drop a value into { }. Python swaps in whatever name holds:
name = "Blaze"
print(f"Hi, {name}!")Hi, Blaze!
{name} became Blaze. No commas, no gaps — the value just slots in.
You can drop in as many values as you like. Here a hero sheet line uses both {name} and {health}:
name = "Blaze"
health = 80
print(f"{name} has {health} HP")Blaze has 80 HP
Two braces, two values filled in. Next we'll even do a little math right inside them.
A full hero sheet. Write {name} and {health} where those values go — and inside the braces you can even compute, like working out the damage:
name = "Blaze"
health = 80
sheet = f"{name} has {health} HP"
print(sheet)
print(f"{name} attacks for {health // 4} damage!")Blaze has 80 HP Blaze attacks for 20 damage!
{name} became Blaze and {health} became 80. Inside the braces you can even compute: {health // 4} worked out 20. No commas, no gaps to fix — just a clean sentence.
f-strings make readable text everywhere. A score line, a greeting, a story sentence, a label on a chart — anywhere you want words and values together, an f-string reads far cleaner than gluing pieces with commas.
Try it yourself
Add a line: f"Welcome, {name}!". Then make a level = 3 box and print f"{name} is level {level}".
The common mistake
Forgetting the f. Without it, "{name} has {health} HP" prints the braces literally — {name} has {health} HP — instead of the values. The little f before the quote is what turns the magic on.
What it unlocks
f-strings dress up print output and show off your variables in a friendly way.