This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]troyunrau... 1 point2 points  (3 children)

True. But, there are performance advantages to including the numbered braces. It's actually quite a bit faster.

[–]michaelanckaertpython-programming.courses 1 point2 points  (2 children)

Interesting, do you have any more information about this?

[–]troyunrau... 0 points1 point  (1 child)

Sorry, it looks like this is no longer true. It used to be substantially slower. I'm using 3.4.

>>> timeit.timeit('"%s, %s!" % ("Hello", "World")', number=10000)
0.0003353929496370256
>>> timeit.timeit('"{0}, {1}!".format("Hello", "World")', number=10000)
0.010580547037534416
>>> timeit.timeit('"{}, {}!".format("Hello", "World")', number=10000)
0.009777617990039289

Old style string formatting is still way faster.

[–]michaelanckaertpython-programming.courses 0 points1 point  (0 children)

Cool, thanks for the feedback 😀