Python f-strings — Formatted String Literals Explained

f-strings let you embed expressions directly inside string literals with f'{value}' syntax. Learn formatting specs, and how they compare to .format() and %.

Published September 18, 2026

An f-string is a string literal prefixed with f that lets you embed Python expressions directly inside curly braces, which are evaluated and inserted at runtime.

name = 'Ada'
age = 30
print(f'{name} is {age} years old')
# Ada is 30 years old

Steps

  1. Prefix the string with f before the opening quote
  2. Place any valid Python expression inside {curly braces} — variables, function calls, or arithmetic
  3. Optionally add a format spec after a colon, like {price:.2f} for two decimal places

How it works

f-strings are evaluated at runtime and compiled more efficiently than str.format() or % formatting, since the expressions are parsed directly into the string literal's bytecode rather than resolved through a separate method call.

Things to watch for

  • f-strings require Python 3.6+
  • Use {value!r} inside an f-string to insert the repr() of a value instead of its str(), useful for debugging

FAQ

Are f-strings faster than .format()?

Yes, generally — f-strings are resolved at compile time into more direct bytecode, making them faster than the equivalent .format() call in most benchmarks.

More Python articles