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

Joshua Marshall jmarshal at mathworks.com
Tue Nov 26 16:32:31 EST 2002


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



More information about the Python-list mailing list