← Reference notes

Python f-strings (formatted string literals)

Python f-strings (formatted string literals)

Summary

An f-string is a string literal with an f prefix that evaluates {expression} at runtime. After a colon you can add a format spec like {x:.2f}, after ! a conversion like {x!r}, and from Python 3.8 a trailing = for debugging output ({x=}). Write {{ and }} to get literal braces.

Draft. License: CC BY 4.0 (this summary). Sources: [S1] Python Software Foundation, "Lexical analysis: f-strings (Python 3 docs)" (PSF License 2.0 docs; restated in our own words, no copied text); [S2] Python Software Foundation, "Format Specification Mini-Language (Python 3 docs)" (PSF License 2.0 docs; restated in our own words, no copied text).

Example

name, total = "Ada", 1234.5
print(f"{name!r} owes ${total:,.2f}")   # 'Ada' owes $1,234.50
print(f"{total=}")                      # total=1234.5

Facts

Caveats

Pointers

Source: https://docs.python.org/3/reference/lexical_analysis.html#f-strings · License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted), condensed and paraphrased; sources: Python Software Foundation, Python 3 documentation, Lexical analysis: f-strings (PSF License 2.0); restated in our own words; Python Software Foundation, Python 3 documentation, Format Specification Mini-Language (PSF License 2.0); restated in our own words

Cite this

Permanent ID: iil:note:zszspfxq

iinventedlight Library. 2026. "Python f-strings (formatted string literals)." iinventedlight Library, iil:note:zszspfxq, version of 2026-11-02. https://iinventedlight.com/library/reference/python-docs/python-f-strings/. License: CC-BY-4.0. Summary of https://docs.python.org/3/reference/lexical_analysis.html#f-strings.

@misc{iil_note_zszspfxq,
  author = {{iinventedlight Library}},
  title = {{Python f-strings (formatted string literals)}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-02},
  url = {https://iinventedlight.com/library/reference/python-docs/python-f-strings/},
  note = {Permanent ID iil:note:zszspfxq. License: CC-BY-4.0. Summary of https://docs.python.org/3/reference/lexical\_analysis.html\#f-strings.},
}

For language models and agents: start at /llms.txt. This page in Markdown: /library/reference/python-docs/python-f-strings.md.