by metrognome · 1y ago · 0 comments
There should be one-- and preferably only one --obvious way to do it.
Python String Formatting in 2025:- t-strings
- f-strings
- %-operator
- +-operator
- str.format()
I see each of these as distinct but overlapping; I'm (slowly) writing a guide to string formatting with all of these in mind, trying to emphasize when I'd choose one over the other. (fwiw I personally avoid % and + these days; $ is pretty uncommon in practice; f-, t-, and .format() all seem to have good unique uses.)
It's definitely true that those four string formatting techniques violate the "one obvious way" advice.
"Situation: There are 14 competing standards...." https://xkcd.com/927/