f-string

A Python string with an f before the opening quote, in which expressions in curly brackets are replaced by their values.

In more detail

f-strings, added in Python 3.6, are the shortest way to format text: any expression can go inside the braces and a format specifier follows a colon, as in f"{price:.2f}". They are evaluated where they are written, so every name used must exist at that point.

Example

name = "Ana"
print(f"Hello, {name}!")

Related terms

Taught in

References