f-string
noun
say it: “EF string” /ˈɛf strɪŋ/
Text with values dropped straight in: put an f before the opening quote and wrap each value in curly braces, as in f"Hi, {name}".
What is an f-string?
An f-string drops values straight into text. Put an f before the opening quote and wrap each value in curly braces.
name = "Jo"
cups = 2
print(f"{name} ordered {cups} coffees") # Jo ordered 2 coffees
In a sentence
- “The receipt line is an f-string: f"{name} ordered {cups} coffees".”
- “An f-string can format money too, as in {total:.2f}.”
Level: Novice · More Python terms at this level
Updated