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

Ian Kelly ian.g.kelly at gmail.com
Tue Aug 25 17:39:02 CEST 2015


On Tue, Aug 25, 2015 at 9:32 AM, Skip Montanaro
<skip.montanaro at gmail.com> wrote:
>
> On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen
> <harvested.address at is.invalid> wrote:
>>
>> 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.
>
>
> You are imagining the whole thing. Either that, or you had some other
> problem with your tuple unpacking which kept it from working. That has been
> a part of the language as far back as I can remember. I started using Python
> around the 1.0 timeframe.

My guess is that Jussi was trying to unpack a sequence of a single
element like this:

    (a) = some_sequence

With the result that a is assigned the whole sequence instead of the
one element, because (a) does not denote a tuple, but merely an
individual parenthesized expression. Any of these would work in its
place:

    (a,) = some_sequence
    a, = some_sequence
    [a] = some_sequence


More information about the Python-list mailing list