Below is what I tested on IPython. The result of print(*(a,a))
is what I expected but not print(*(a))
. I though print(*(a))
would give [1,2]
. The background is that I have some function taking a list as an argument and this "unexpected" unpacking behavior caused errors of mismatch in argument numbers. I can work around it by using ([a])
as shown by the last print command. However, I think this inconsistent unpacking behavior is very unpythonic. Can someone explain it? Thanks.
In [82]: a=[1,2]
In [83]: print(*(a))
1 2
In [84]: print(*(a,a))
[1, 2] [1, 2]
In [85]: print (*([a]))
[1, 2]