[a,b,c,d] = 1,2,3,4

Jean-Michel Pichavant jeanmichel at sequans.com
Tue Aug 25 16:59:25 CEST 2015

----- Original Message -----
> From: "Joel Goldstick" <joel.goldstick at gmail.com>
> its called list unpacking or packing (?)
> the right side is considered a tuple because of the commas
> >>> a = 1,2,3
> >>> a
> (1, 2, 3)
> >>> a[1]
> 2

To add to Joel's answer, the right side can be *any* sequence, and is not restricted to lists or tuples.

a, b, c = (x for x in range(3)) # a generator for instance

That would be a generator unpacking combined with a tuple packing (is packing restricted to tuples and lists ? probably)



The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

More information about the Python-list mailing list