r/ProgrammerHumor • • Aug 26 '20

Python goes brrrr

Post image
59.2k Upvotes

789 comments sorted by

View all comments

797

u/geeshta Aug 26 '20

f"Python goes b{'r'*10}"

367

u/Jeb_Jenky Aug 26 '20

This made my nips so hard.

314

u/xDarkFlame25 Aug 26 '20

Ah yes fstrings, the ultimate fetish.

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?

78

u/GenericRedditor12345 Aug 26 '20

If you don’t need the functionality of an f string :p They’ve been optimized to be faster than the other formatting methods IIRC.

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)
→ More replies (1)
→ More replies (12)
→ More replies (4)
→ More replies (2)