• Operator %s VS str.format()

Question related to mission Building Base

 

Many users dont know, what in docs.python.org/3.4/ paragraph 4.7.2. wrote:

The formatting operations '%' exhibit a variety of quirks that lead to a number of common errors (such as failing to display tuples and dictionaries correctly). Using the newer str.format() interface helps avoid these errors, and also provides a generally more powerful, flexible and extensible approach to formatting text.

Operator '%' is faster than str.format() http://blog.lerner.co.il/relative-speeds-str-format/ But str.format() can be shorter:

From my 'task.building-base' solution:

# operator '%'
return '%(name)s(%(south)s, %(west)s, %(width_WE)s, %(width_NS)s, %(height)s)' % self.__dict__

# operator 'str.format'
return '{name}({south}, {west}, {width_WE}, {width_NS}, {height})'.format(**self.__dict__)

What are you thinking about it?