Guido van Rossum wrote:
we might propose (as the OP did) that this:

  a, b, c += x, y, z

could be made equivalent to this:

  a += x
  b += y
  c += z

But not without violating the principle that

   lhs += rhs

is equivalent to

   lhs = lhs.__iadd__(lhs)

Granted, this rule inevitably leads to an "unpacking sequence
of wrong length" error in the case we're considering, so
we wouldn't be changing any useful existing semantics, but
it's still making the rules more complicated.

but the question is, what would this do?

  a, b, c += x

they might think that this is a clever way to increment three variables at once:

  a, b, c += 1

Someone who thinks that might also think

    a, b, c = 1

is a way to assign 1 to a, b and c, but we don't seem to
be worried about that possible misunderstanding.

This does raise the question of what the corresponding
generalisation of multiple assignment targets might be.
Would you write

   a += b += c += 1

or

   a = b = c += 1

? And if the former, do we allow different operations
on each target, e.g.

   a += b -= c *= 2

?

--
Greg
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to