I came across a negligible but convenient new string formatting feature introduced within PEP 498 (Literal String Interpolation) in Python 3.6. Essentially, it is a way of string formatting that lets you use embedded expressions that are evaluated at run time inside string constants. Here is what the official description looks like:

F-strings provide a way to embed expressions inside string literals, using a minimal syntax. It should be noted that an f-string is really an expression evaluated at run time, not a constant value. In Python source code, an f-string is a literal string, prefixed with ‘f’, which contains expressions inside braces. The expressions are replaced with their values.

But don’t worry, the introduction of this new feature does not intend to push forward removal or deprecation of any of the existing string formatting mechanisms, i.e. %–operator and str.format(). So why should you use it?

This PEP is driven by the desire to have a simpler way to format strings in Python. The existing ways of formatting are either error prone, inflexible, or cumbersome. %-formatting is limited as to the types it supports. Only ints, strs, and doubles can be formatted. All other types are either not supported, or converted to one of these types before formatting.

Another obvious advantage is that it is short, explicit and easy to read. It is faster compared to the traditional string formatting methods and presumably less error prone. On the downside I guess the most noteworthy disadvantage right now is that there is (of course) no backward compatibility. Here are a couple examples of what you can do with f–strings:

planet = 'Mars'
f'Welcome to planet {planet}!'
# 'Welcome to planet Mars!'

import datetime
date = datetime.date(2035, 1, 12)
f'You arrived on {date}, which was a {date:%A}.'
# 'You arrived on 2035-01-12, which was a Friday.'

speed, distance = 5e3, 56e9
seconds2days = lambda x: x / 3600 / 24
f'It took you {seconds2days(distance / speed):.2f} days to get here.'
# 'It took you 129.63 days to get here.'

# Raw and f-strings may be combined for example to build up regular expressions:
header = 'Subject'
# 'Subject:\\s+'

# If you are writing SQL queries, I like the explicitness and brevity...
column, name, table, condition = 'user', 'spaceman', 'users', f'name = {name}'
f'SELECT {column} FROM {table} WHERE {condition}'
# 'SELECT user FROM users WHERE name = spaceman'

Looks pretty cool to me!

Further Reading