[Tutor] t = (1, *(2, 3))
Steve Willoughby
steve at alchemy.com
Thu May 14 21:43:34 CEST 2009
On Thu, May 14, 2009 at 11:10:53AM -0700, Jabin Jezreel wrote:
> > Why not just write is simply as (1, 2, 3) instead of
> > the confusing (1, *(2, 3))?
>
> It is a contrived example. In practice it would be
> something more like:
>
> >>> def ts(*t):
> ... return t
> ...
> >>> x = (2, 3)
> >>> y = (1, *x)
> File "<stdin>", line 1
> SyntaxError: can use starred expression only as assignment target
> >>> y = ts(1, *x)
> >>> y
> (1, 2, 3)
But you can already do that without needing to extend * notation
to work like that, so in the Pythonic spirit of there only being
one obvious/best/clear way to do something...
y = (1,) + x
why does that operation have to be constructed as
y = (1, *x)?
>
>
> > Don't say that (2, 3) might be a variable, it
> > won't work without breaking python object model.
> > If such construct creates a new tuple, it would
> > need to break python's object model [...]
>
> Break how?
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Steve Willoughby | Using billion-dollar satellites
steve at alchemy.com | to hunt for Tupperware.
More information about the Tutor
mailing list