Python 2.6 introduced the str.format() method with a slightly different syntax from the existing %
operator. Which is better and for what situations?
Pyt
As of Python 3.6 (2016) you can use f-strings to substitute variables:
>>> origin = "London"
>>> destination = "Paris"
>>> f"from {origin} to {destination}"
'from London to Paris'
Note the f"
prefix. If you try this in Python 3.5 or earlier, you'll get a SyntaxError
.
See https://docs.python.org/3.6/reference/lexical_analysis.html#f-strings