Explainer: f-strings

F-strings (formatted string literals) provide a concise and convenient way to embed expressions inside string literals for formatting.

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

# Decimal formatting
price = 19.99
print(f"The total is: ${price:.2f}")

The :.2f syntax is particularly useful for currency, as it forces the float to display exactly two decimal places.

Struggles with Scope

One thing that tripped me up early was the difference between local and global scope. If you define a variable inside a function, you can't access it outside unless you return it.