f-strings and Formatting
Putting values inside strings, and the small format language that controls how each one is printed.
Overview
The prefix does the work
f"{name} scored {score}"
The f before the quote is what turns braces into slots. Without it you get the literal characters. Inside the braces goes any expression — a variable, a method call, arithmetic — evaluated at that point and inserted.
That is the whole idea, and it is why f-strings replaced everything before them: the value appears in the source where it appears in the output. Concatenation with + scatters the sentence across quotes and plus signs, and % and .format() push the values to the end, away from the slots they fill.
fstrings.py
formatting_compare.py
Worth knowing
f prefix is required. Without it the braces are just braces.:.2f fixes two decimal places, :, adds thousands separators, :>8 right-aligns in eight columns.f"{x = }" prints both the expression and its value - the fastest debug print there is.