PYTHON TUTORIAL
Python F-String Codes I Use Every Day
A few examples that will save the day probably* 95% of time
*I don’t have the actual data but seriously, I bet you’ll find those tips useful more often than not!
I use f-strings
every day. The irony is I also every day end up searching the Web to find the correct format to use. Until one day I thought a better use of my time would be to create a cheat sheet of the most common formatting cases — AKA this article. It covers the following:
- integers, floats, numbers and scientific notation
- percentages %
- dates
- padding
- adding +/- sign in front of a number
It’s important to note that the f-strings
were first introduced in Python 3.6 (PEP 498 if you REALLY must know) so make sure to check the Python version first, if things don’t work for you.
The format
The most basic f-string
format goes like this: