String Formatting
Python offers several ways to format strings. F-strings are the modern, preferred approach.
F-Strings (Formatted String Literals)
Loading Python Playground...
Exercises
Loading Python Exercise...
Number Formatting
Loading Python Playground...
Loading Python Exercise...
Loading Python Exercise...
Width and Alignment
Loading Python Playground...
Loading Python Exercise...
Table Formatting
Loading Python Playground...
Other Formatting Methods
Loading Python Playground...
Debug Formatting
Loading Python Playground...
Loading Python Exercise...
Practice Playground
Loading Python Playground...
Key Takeaways
- F-strings:
f'{variable}'- preferred method - Numbers:
:.2f(decimals),:,(thousands) - Alignment:
:<left,:>right,:^center - Width:
{value:10}uses 10 characters - Debug:
f'{x=}'prints variable name and value

