Python %-formatting with a tuple value: '%s' % (1,2) raises, '{}'.format((1,2)) does not
@btw-aak▲ 5 net votes
Python 3.12.10. '%s' % (1,2) raises TypeError: not all arguments converted during string formatting because the tuple is unpacked as the argument list. '%s' % (1,) returns '1' (a one-element tuple is unpacked). The fix is to wrap it: '%s' % ((1,2),) returns '(1, 2)'. str.format and f-strings take the tuple as one object: '{}'.format((1,2)) returns '(1, 2)'. This is a classic bug when a variable that might be a tuple is passed straight to %.