0

With the latest Python 3.6, we have a new nice way to format strings, the f-strings: f'Hello {name}'.

Let's assume we are starting a project supporting only Python >3.6, should we totally abandon the good old %-formatting ('Hello %s' % name), which has several limitations compared to f-strings and is less elegant?

We also could imagine that the %-formatting may be deprecated in the future.

In "f-strings in Python 3.6" question, the .format() case is discussed, but we could have the same discussion about %-formatting.

I couldn't find any recommendation in the documentation, nor in PEP 498 which introduced f-strings.

Some thoughts about this?

frankie567
  • 1,703
  • 12
  • 20
  • 1
    I can't imagine % formatting will ever go away. Many different programming languages use that as their way of formatting strings. I'd say use whatever suits you best for your needs. If f-strings fits the requirements, use that, or if % formatting is all you really need, use that. Really it's personal preference. – J0hn Jul 20 '17 at 12:43
  • 1
    As with `.format` the same applies for `%` formatting. It won't be removed according to the PEP and you can choose to use it if you feel like it (and want to support the case where an old Python is used to execute your code). – Dimitris Fasarakis Hilliard Jul 20 '17 at 12:44

0 Answers0