DEV Community

Toolloom
Toolloom

Posted on • Originally published at toolloom.com on

Level Up Your Python Strings

If you're still using .format() or % for string interpolation in Python, it's time to fully embrace f-strings. They aren't just more readable; they're actually faster because they're evaluated at runtime rather than being constant strings that require a function call.

A little-known trick is the = specifier introduced in Python 3.8. Writing f"{variable=}" will output both the variable name and its value (e.g., variable=10). It’s the ultimate "quick and dirty" debugging tool when you don't want to fire up a full debugger.

Top comments (0)