Python f-strings cheat sheet

Python f-strings The image above is in SVG format, so it is infinitely scalable: zoom in at will! Some further notes on Python f-strings: Never use the f or F formats for floating point numbers. Use g instead. The problem is the f format fixes the number of digits after the decimal separator and that is most probably not what you want. >>> f'{0.00001234:.2f}' # Gets converted to zero 0.00 >>> f'{0....

April 17, 2023 · 1 min · Lucas Viana