[Tutor] t = (1, *(2, 3))

Lie Ryan lie.1296 at gmail.com
Thu May 14 15:07:16 CEST 2009


Jabin Jezreel wrote:
> I am not allowed to do
>>>> t = (1, *(2, 3))
> 
> But I am allowed to do
>>>> def ts(*t):
> ....    return t
> ....
>>>> ts(1, *(2, 3))
> (1, 2, 3)
> 
> I realize I can do
>>>> (1,) + (2,3)
> (1, 2, 3)
> 
> What is the rationale behind not having t = (1, *(2, 3))
> have the same semantics as the "ts" case above?

In the face of ambiguity, refuse the temptation to guess?

I guess because it is not clear what (1, *(2, 3)) should mean. 
Parentheses when used for function call has different semantic then when 
parentheses is used for tuple syntax. Parentheses in function is part of 
the calling syntax, while parentheses in tuple is used only for grouping.

PS: anyway I just realized that since tuple is immutable, having (1, 
*(2, 3)) be (1, 2, 3) would violate immutability. Maybe a list would be 
a better example.



More information about the Tutor mailing list