Why not a, b += i, j? (augmented assignment via tuple unpacking)

John Roth johnroth at ameritech.net
Tue Nov 26 21:01:25 EST 2002


"Joshua Marshall" <jmarshal at mathworks.com> wrote in message
news:as0p9f$3c7$1 at ginger.mathworks.com...
> Grant Edwards <grante at visi.com> wrote:
> > In article <KbRE9.534$RQ3.26615908 at newssvr17.news.prodigy.com>,
Steven Rumbalski wrote:
>
> >> In python I can write:
> >>
> >> a, b = i, j
> >>
> >> but the following is not legal:
> >>
> >> a, b += i, j
> >>
> >> Is there a reason that allowing this would be bad?
>
> > If it were allowed, what do you propose it would do?
>
> Maybe:
>
>   a, b += i, j
>
> is equivalent to
>
>   tmp = j
>   a += i
>   b += tmp
>
> I use a temp because of this sort of situation:
>
>   a, b += b, a

I'd think it would be equivalent to:

a += i
b += j

the corner case you mention should behave
the same as

a, b = b, a

Why make it more complicated than it has
to be?

John Roth





More information about the Python-list mailing list