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

Joshua Marshall jmarshal at mathworks.com
Tue Nov 26 17:01:19 EST 2002


Grant Edwards <grante at visi.com> wrote:
> In article <as0p9f$3c7$1 at ginger.mathworks.com>, Joshua Marshall wrote:

>> Maybe:
>> 
>>   a, b += i, j
>> 
>> is equivalent to
>> 
>>   tmp = j
>>   a += i
>>   b += tmp

> To me, that would be a bit counter-intuitive, since

>   ((a,b) + (i,j)) equals (a,b,i,j)  rather than   ((a+i),(b+j))

Counter-intuitive even though:

  >>> a = 3
  >>> b = 4
  >>> a, b = b, a
  >>> a
  4
  >>> b
  3

?



More information about the Python-list mailing list