AnyCompiler
← Blog

September 6, 2026

f-strings vs. .format() vs. % Formatting: Which Should You Actually Use in 2026?

Python has accumulated three different ways to insert variables into strings over its history, and all three still work today. Here's what they look like side by side, producing the exact same output.

name = "Maya"
age = 29

print(f"{name} is {age} years old")
print("{} is {} years old".format(name, age))
print("%s is %d years old" % (name, age))
Output
Maya is 29 years old
Maya is 29 years old
Maya is 29 years old

% formatting — the oldest, avoid for new code

"%s is %d years old" % (name, age) is inherited from C's printf style. It still works, but it's rarely the right choice for new code — the % operator on strings has awkward edge cases with tuples and dicts, and it's largely considered legacy at this point.

.format() — flexible, but verbose

"{} is {} years old".format(name, age) fixed the worst problems with % formatting and is still common in older codebases, but it separates the values from where they're used in the string, which makes longer strings harder to read at a glance.

f-strings — the modern default

f"{name} is {age} years old" puts the variable directly where it's used, is faster than both alternatives, and supports inline expressions (f"{age + 1}" works directly). f-strings were added in Python 3.6 and have been the recommended default ever since — reach for one unless you have a specific reason not to.

The full Strings and String Methods lesson in our free Python course covers f-strings alongside indexing, slicing, and the other string methods you'll use constantly.