Why would I ever use .format(...)? It's worse than %s and slower. There are now 2 methods in my book and 1 that I can use because I write Python 2/3 code.
That's interesting. I never use % formatting. It's a fairly gross overload of the modulus operator, and has weird syntax. str.format is explicit and clear, and if it's slower than % it's negligible.
It's very verbose and requires me to create a dictionary that I don't have in order to write the string part in a way that looks sane. I really want to use f-strings, but Python 2 doesn't support it...
f-strings bother me. Of all the complaints about the complaints in the article, the multiple string formatting complaint is legit. Python 2 had one obvious way to do string formatting. Python 3.6 has three.
I really am not bothered at all by that. Just use the newest one (that supports your target Python versions), and you're all done. Learning to read and recognize the other two is trivial, too.
5
u/LpSamuelm Nov 24 '16
That's interesting. I never use
%formatting. It's a fairly gross overload of the modulus operator, and has weird syntax.str.formatis explicit and clear, and if it's slower than%it's negligible.