f-string
Embeds a variable/expression inside text.
Syntax
f"text {value} text"Description
If you put f before the quote, the variable or expression you write inside the curly braces { } is automatically inserted into the text. The most readable way to combine text.
Returns
The formatted text (str).
Example
Loading editor…
Expected output
Alex today got 95 score Total: 15
When to use?
When combining variables with text and printing them; it saves you from fiddling with +.
Common mistakes
- ⚠️ Forgetting the leading f: "{name}" is printed as-is, f"{name}" inserts its value.