r/ProgrammerHumor • • Aug 26 '20

Python goes brrrr

Post image
59.2k Upvotes

789 comments sorted by

View all comments

Show parent comments

155

u/AinsleyBoy Aug 26 '20

I fucking love fstrings. I use them so much

42

u/Moldy_pirate Aug 26 '20

Is there ever a reason to use a “regular” string rather than an f”string?

22

u/thirdegree Violet security clearance Aug 26 '20

Logging, there you want to do like:

logging.info("value1: %s, value2: %s", 1, 2)

This is because the formatting is only done if the log line will actually be emitted. It can be a significant performance boost if you have a lot of logging.

5

u/[deleted] Aug 26 '20

You can always have a lazy evaluation, using str::format, i. e. log("python goes b{0}", 'r'*10). The string would only format if it were to be used.

→ More replies (3)