Python f-Strings: Formatting Examples
To format a string in Python, put an f before the quotes and write any variable or expression inside curly braces, like f"Hello {name}". Add a colon and a format spec to control how the value looks, for example f"{price:.2f}" for two decimal places. This guide collects the f-string formatting examples I reach for most: numbers, alignment, dates, debugging and the newer features in Python 3.12 and 3.14. Before f-strings, I was gluing strings together with + and str(), which got messy quickly. F-strings fixed that.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in