Why do I get "TypeError: not all arguments converted during string formatting" trying to format a tuple?

python

Solution

>>> thetuple = (1, 2, 3)
>>> print("this is a tuple: %s" % (thetuple,))
this is a tuple: (1, 2, 3)

Making a singleton tuple with the tuple of interest as the only item, i.e. the `(thetuple,)` part, is the key bit here.

Problem

I want to use `%`-style string formatting to print a tuple: ``` tup = (1,2,3) print("this is a tuple: %s." % (tup)) ``` I expect it to print like `This is a tuple: (1,2,3).`, but instead I get an error that says `TypeError: not all arguments converted during string formatting`. What is wrong, and how do I fix it? In editing this question for clarity and modernization, I preserved one interesting aspect of the original example: the parentheses around `tup`. These are not necessary for the `%` syntax, and also do not create a tuple. It's possible that OP understood that the tuple wrapping (described in the answers here) was necessary, but simply got it wrong. For more information on that issue, see How to create a "singleton" tuple with only one element.

Original source

Related problems