Unpacking Tuples

Chris Rebert clp2 at rebertia.com
Mon Nov 30 03:26:44 EST 2009


On Mon, Nov 30, 2009 at 12:17 AM, Joel Davis <callmeclaudius at gmail.com> wrote:
> I hate to post such a simple Q and A here, but I seriously can't find
> it anywhere. Python (unsure of starting with which version) enables
> the remainder of the tuple to be placed in a "catch-all", for example:
>
>
>>> myTuple = (1,2,3,4)
>>> varOne, varTwo, *remaindingTuple = myTuple.
>
> where the values left unpacked get thrown into a tuple referenced to
> by "remaindingTuple" I included the asterix because it seems like I
> remember that being the operator that specifying the tuple's dumping
> ground. Which brings me to my two questions:
> 1) what's the syntax for this operation

Exactly as you showed above (well, minus the period obviously).

2) what version does it start with?

Python 3.0

It might be backported into 2.7 when it gets released:
http://bugs.python.org/issue2340

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list