5. String interpolation

Prefer f-strings for most string interpolation in modern Python. They are usually the clearest option.

F-strings keep the literal text and embedded values in one place with very little ceremony. That tends to be easier to scan than older formatting styles, especially once expressions or format specifiers appear.

5.1. Don’t do this

1name = 'John'
2food = 'pizza'
3sport = 'tennis'
4
5sentence = '{} likes to eat {}. {} likes to play {}.'.format(name, food, name, sport)

5.2. Do this

1name = 'John'
2food = 'pizza'
3sport = 'tennis'
4
5sentence = f'{name} likes to eat {food}. {name} likes to play {sport}.'