= 2
a = 3 b
Python f-strings
Here are some examples of f-strings in Python inspired by a post and a cheat sheet.
f"{a} + {b}"
'2 + 3'
f"{a=} and {b=}"
'a=2 and b=3'
f"a + b = {a+b}"
'a + b = 5'
Curly brackets in an f-string
= 123
n
f'{{}}-{n}-{{{n}}}'
'{}-123-{123}'
Number formatting
= 1234567890.1234
var
f'{var:,}'
'1,234,567,890.1234'
f'round: {var:.2f}'
'round: 1234567890.12'
f'comma: {var:,}'
'comma: 1,234,567,890.1234'
f'comma: {var:,.2f}'
'comma: 1,234,567,890.12'
import datetime
= datetime.datetime(2026, 2, 21, 19, 45, 30)
dt
f'{dt}'
'2026-02-21 19:45:30'
f'{dt:%Y-%m-%d}'
'2026-02-21'
f'{dt.isoformat()}'
'2026-02-21T19:45:30'