Tuples are expanded as multiple arguments when passed to print statement after %

Below the tuple (1, 2, 3) is getting expanded as 3 arguments and the format representation is expecting to have 3 %s or %r to be printed,

>>> print "%r" % (1, 2, 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
>>> print "%s" % (1, 2, 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
>>> print "%s" % str((1, 2, 3))
(1, 2, 3)

Comments

Popular posts from this blog

Multiple repeat error when the regex has multiple wildcards in python re module

Avoid using global/class-level mutable datatypes like list/dicts

Weakref proxy is for instance only ...