I've recently watched a Python tutorial in which the author kept juggling various Python string formatting expressions and I was struck by a thought:
Why are there so many string formatting flavours in Python?
- There's the C language
printf
based approach (which, by the way, in various sources is cited as being deprecated and scheduled for removal but there's an abundance of its examples in the standard Python documentation (!)). - On the other hand, there's the
C#
derived.format()
way of handling strings. - Finally, as of the advent of Python 3.6, we've been given the
formatted f-string literal
, known as thef-string
. - Some also include the
string
module but that seems an overkill to me.
As I found out here, the first two aforementioned techniques both differ and overlap each other, depending on the use.
And last but not least, isn't this opulence of methods contradictory to one of Python's declarations from the import this
?
There should be one-- and preferably only one --obvious way to do it.
Correct me if I'm wrong, but this is inherently "un-Pythonic" in a way.
Would readers offer their thoughts on this, preferably backed up with some relevant examples?