Python string formatting: f-strings to the rescue

Just discovered f-strings for Python string interpolation – much, much better than any of the other formatting techniques such as .format or %.

Example:

print(f'{name} is {age} years old')
Jon is 21 years old

I’ve written a load of examples and notes in an interactive Jupiter notebook, mainly for my own reference:

https://gitlab.com/cds/pythonlearning/blob/master/fstring.ipynb

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s