I often use Python\'s print
statement to display data. Yes, I know about the \'%s %d\' % (\'abc\', 123)
method, and the \'{} {}\'.format(\'ab
print
is a statement in Python 2.x and does not support the *
syntax. You can see this from the grammar for print
listed in the documentation:
print_stmt ::= "print" ([expression ("," expression)* [","]] | ">>" expression [("," expression)+ [","]])
Notice how there is no option for using *
after the print
keyword.
However, the *
syntax is supported inside function calls and it just so happens that print is a function in Python 3.x. This means that you could import it from __future__:
from __future__ import print_function
and then use:
print(*l)
Demo:
>>> # Python 2.x interpreter
>>> from __future__ import print_function
>>> l = [1, 2, 3]
>>> print(*l)
1 2 3
>>>