Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Zen of Python in 2025:

  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()



And $-strings (PEP 292) as well. :-)

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.)


The last three generally shouldn't be used (`+` is sometimes fine, but not really for formatting), but I doubt we would ever get a py4 that removes them, given the stomachaches that py3 caused. It does feel odd that a t-string is just an f-string without args applied.


It's my understanding that they're still recommended for logging since with f-strings you always pay the formatting cost (but with str.format it's deferred).


t-strings aren't really like these others.

It's definitely true that those four string formatting techniques violate the "one obvious way" advice.


I could scarcely believe this new t-string wasn't a joke. As an occasional, grudging Python programmer, I rue the accretion of string formatters over the years. My code bears the history of successive, imperfectly understood (by me)formatters.

"Situation: There are 14 competing standards...." https://xkcd.com/927/




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: