1 / 10

f-strings Can Do More Than Insert

You already know f"{price}" drops a value into text. Add a colon and a format spec right after the variable, and you control exactly how that value looks:

python
price = 19.9
print(f"{price:.2f}")

.2f means "show this as a fixed-point number, with exactly 2 digits after the decimal."