Write a formalized f-string after PEP 701
Answer: A formatted string literal, also called an f-string, is prefixed with f or F. Those literals do not have a constant value. They may contain replacement fields delimited by curly braces {}. PEP 701 lifts some of the restrictions originally formulated in PEP 498.
Replacement fields
Replacement fields contain expressions which are evaluated at runtime. PEP 701 provides a formalized grammar for f-strings that can be integrated into the parser directly.
Side effects of the formalization
The formalization will have some small side-effects on how f-strings are parsed.
| f-string | PEP 701 | |---|---| | f or F | Prefix on a formatted string literal | | replacement fields | Delimited by curly braces | | PEP 498 | Original restrictions that PEP 701 lifts | | parser | Where the formalized grammar is integrated |
See also
Claims
- id: C1 claim: PEP 701 lifts some of the restrictions originally formulated in PEP 498. source: S1 evidence: "lift some of the restrictions originally formulated in PEP 498"
- id: C2 claim: It provides a formalized grammar for f-strings that can be integrated into the parser. source: S1 evidence: "a formalized grammar for f-strings that can be integrated into the parser directly"
- id: C3 claim: An f-string is a string literal prefixed with f or F, with replacement fields in braces. source: S2 evidence: "A formatted string literal or f-string is a string literal"
Sources
- [S1] PEP 701 – Syntactic formalization of f-strings. Python PEPs. https://peps.python.org/pep-0701/ . License: Public-Domain. Accessed 2026-11-19.
- [S2] Lexical analysis. Python docs. https://docs.python.org/3/reference/lexical_analysis.html . License: PSF-2.0. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python PEPs, PEP 701 – Syntactic formalization of f-strings; Python docs, Lexical analysis. Public-Domain; PSF-2.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python PEPs, PEP 701 – Syntactic formalization of f-strings; Python docs, Lexical analysis. Public-Domain; PSF-2.0.
Cite this
iinventedlight. 2026. "Write a formalized f-string after PEP 701." iinventedlight Library, iil:note:sdz9yqz7, version of 2026-11-19. https://iinventedlight.com/library/notes/pep-701-fstring/. License: CC-BY-4.0.
@misc{iil_note_sdz9yqz7,
author = {{iinventedlight}},
title = {{Write a formalized f-string after PEP 701}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/pep-701-fstring/},
note = {Permanent ID iil:note:sdz9yqz7. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- pep-701-fstring.table.json (table; CC-BY-4.0)
- pep-701-fstring.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/pep-701-fstring.md.