The error occurs because (a)
is just a value surrounded by parenthesis. It’s not a new tuple object.
Thus, '%d %d' % (*a)
is equivalent to '%d %d' % * a
, which is obviously wrong in terms of python syntax.
To create a new tuple, with one expression as an initializer, use a comma after that expression:
>>> '%d %d' % (*a,)
'1 2'
Of course, since a
is already a tuple, we can use it directly:
>>> '%d %d' % a
'1 2'