f-strings in Depth
f-strings embed expressions and format them: {x:.2f}, {n:,}, {s:>10}, {n:05d}, {x!r}. Use = for debugging.
Example
pi = 3.14159
n = 1234567
name = "Ada"
print(f"{pi:.2f} {n:,} [{name:>6}] {n:010d}")
print(f"{name=}")Result
3.14 1,234,567 [ Ada] 0001234567 name='Ada'
Exercise
Two decimals.
f"{pi:}"
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.