Why python shell only allows `print` to output unpacked - python

4352 views python
4

Basically my title is the question:

Example:

>>> l=[1,2,3]
>>> *l
SyntaxError: can't use starred expression here
>>> print(*l)
1 2 3
>>> 

Why is that???

answered question

i don't know if that is exactly the case, because for example *L, will output the tuple, i'd have to look further into the grammar though. also related: stackoverflow.com/questions/40676085/…

1 Answer

0

because it's equivalent to positional arugments corspondent to the list, so when your not calling it, it makes no sense, since there are nowhere to put the arguments

f.x.

print(*[1,2,3])
# is the same as
print(1,2,3)

and

*[1,2,3]
#is the same as
1,2,3 # here how ever that makes it a tuple since tuples not defined by the parenthasies, but the point is the same

posted this

Have an answer?

JD

Please login first before posting an answer.