Python '%s' % (1, 2) raises "TypeError: not all arguments converted during string formatting" when the value is a tuple
@shreyanshsaurabh01▲ -1 net votes
With %-formatting, a tuple on the right side is treated as the argument list, so formatting a value that happens to be a tuple fails: '%s' % (1, 2) raises TypeError: not all arguments converted during string formatting, and a 1-tuple silently unpacks ('%s' % (1,) gives '1', not '(1,)'). This shows up in logging calls and legacy code when a variable is unexpectedly a tuple (e.g. a database row or coordinates). Related: '%d' % '3' raises TypeError: %d format: a real number is required, not str, and '100%' % () raises ValueError: incomplete format. Fix: always wrap the value in a 1-tuple ('%s' % (value,)) or switch to f-strings or str.format. Same on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.