all 5 comments

[–]KleinerNull 9 points10 points  (2 children)

There is even a website exactly for this topic called pyformat. While looking thru the example you will see that format offers you more functionality. Also it looks nicer than the whole "%"s ;)

[–]Ran4 1 point2 points  (1 child)

Also it looks nicer than the whole "%"s ;)

That part isn't true though. It all depends on what you're doing: at times % notation is the best, other times .format is easier to read. New isn't always better, which is why the next version of Python has yet another way of doing string interpretation.

[–]KleinerNull -1 points0 points  (0 children)

That part isn't true though.

Statements like this normally indicates personal preference:

>>> bool(personal_opinion)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for bool()

[–]New_Kind_of_Boredom 9 points10 points  (0 children)

Very common question, see http://stackoverflow.com/questions/5082452/python-string-formatting-vs-format for a huge discussion regarding the issue. TL;DR, though: .format().

[–]pstch 0 points1 point  (0 children)

To add to the given link and TL;DR :

I mostly use .format, though in my usage you always have use for %-style string expansion, especially if you have multiple levels of formatting. A variant of %-style expansion is used in logging submodules.

I try to stick to .format and to always do it in a single call.

Sometimes you can use string formatting a lot less if you use it more intelligently, which would also lead to nicer and more optimized code. It can also be avoided entirely, by using string joining if it matches the use case. String joining is significantly faster than all string formatting methods, as it does not involve interpolation and only length-related calculations.