←back to thread

620 points tambourine_man | 1 comments | | HN request time: 0.209s | source
Show context
metrognome ◴[] No.43754478[source]
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()

replies(4): >>43754501 #>>43754671 #>>43756716 #>>43756756 #
a_t48 ◴[] No.43754501[source]
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.
replies(1): >>43756254 #
1. alfalfasprout ◴[] No.43756254[source]
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).