Sponsored Reserved space — layout preview until AdSense is connected

F-string formatting

Embed variables and expressions inside readable f-strings.

5 lines 4 views 1 copies Updated May 23, 2026
Try in editor

How it works

F-strings (formatted string literals) are the preferred way to build text in modern Python.

Put an f before the opening quote, then wrap values in curly braces. You can call methods and use format specifiers like :.2f for two decimal places.

They are faster to read than concatenation and safer than old %-style formatting.

Python
Try in editor
name = "Ada"
score = 97.5
label = f"{name} scored {score:.1f}%"
print(label)
print(f"Next year: {2026 + 1}")

Sponsored

Sponsored Reserved space — layout preview until AdSense is connected

Run this sample

Open the browser IDE to tweak the example and see results without installing anything.

Open editor

More from Strings & text