Home › Python Tutorial › Python number formatting
Python number formatting
Control how numbers look.
Inside an f-string, :.2f shows two decimals and :, adds thousands separators. str.format is the older way to do the same.
Example code
price = 4.5
qty = 3
print(f"Total: {price * qty:.2f}")
print(f"Big: {1234567:,}")
print("{} has {} items".format("Cart", qty))