[Tutor] t = (1, *(2, 3))
Alan Gauld
alan.gauld at btinternet.com
Thu May 14 13:02:59 CEST 2009
"Jabin Jezreel" <jabinjezreel at gmail.com> wrote
> I am not allowed to do
> >>> t = (1, *(2, 3))
Just to be clear, what do you think this means?
What would you expect to happen?
> But I am allowed to do
> >>> def ts(*t):
> ... return t
> ...
> >>> ts(1, *(2, 3))
> (1, 2, 3)
What do you think is happening here that is different?
> I realize I can do
> >>> (1,) + (2,3)
> (1, 2, 3)
And how does this relate to the use of the asterisk?
Is this what you expect the asterisk version above to do?
> What is the rationale behind not having t = (1, *(2, 3))
> have the same semantics as the "ts" case above?
That I don't know. The asterisk notation can only be used
for unpacking function arguments, but why it is limited to
that role I don't know...?
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list