PYTHON TUTORIAL

Python F-String Codes I Use Every Day

A few examples that will save the day probably* 95% of time

Pawel Jastrzebski
Geek Culture
Published in
8 min readJan 14, 2023

--

*I don’t have the actual data but seriously, I bet you’ll find those tips useful more often than not!

Medium article cover

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:

printing f-strings: template

--

--

Pawel Jastrzebski
Geek Culture

I use Python 🐍 and Inkscape 🗻 for data viz 🖼 • matplotlib fan • I share tips, tutorials & articles - let me teach you something • Don't be a stranger 👋