Unpacking only works when you are inside a function call:
>>> def foo(a,b,c):
... pass
...
>>> foo(*[1,2,3])
>>>
Using it elsewhere will cause an Error:
>>> (*[1,2,3])
File "<stdin>", line 1
(*[1,2,3])
^
SyntaxError: invalid syntax
In Python 2.7, print
is not a function, it is a statement. As far as the interpreter is concerned, this:
print(*[1,2,3])
Is syntactically equivalent to this:
print *[1,2,3]
Which is invalid. In Python 3.X, print
is now a function, so unpacking will work.
>>> print(*[1,2,3])
1 2 3
You can port the functional print
back to 2.7 by importing from the future:
>>> from __future__ import print_function
>>> print(*[1,2,3])
1 2 3