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

Jussi Piitulainen harvested.address at is.invalid
Tue Aug 25 17:24:23 CEST 2015


"ast" writes:

>>>> [a,b,c,d] = 1,2,3,4
>>>> a
> 1
>>>> b
> 2
>>>> c
> 3
>>>> d
> 4
>
> I have never seen this syntax before. Is it documented.
> Is there a name for that ?

I remember being unhappy when a similar assignment with round brackets
turned out to be invalid syntax. Then I learned (in this newsgroup) that
square brackets would work, and so they did, and then I was happy again,
though it felt a bit inconsistent. When I try it today, round brackets
also work, both in 2.6.6 and 3.4.0 - no idea what version it was where
they failed or if I'm imagining the whole thing.

The page that Joel Goldstick cited claims that Guido van Rossum himself
has called the left side of a statement like "w,x,y,z = t3" (no brackets
on that page) "the list of variables" (but their link to the evidence is
dead).


More information about the Python-list mailing list