Chris Angelico writes:

 > When you have completely different variables, sure. But what if - like
 > in the swap example - they're the same variables?
 > 
 > a, b, c += b, c, a

Good point.

    a, b, c = a + b, b + c, c + a

is "good enough" for this particular case, I'd say, and has the
advantage that it immediately generalizes to mixed operations:

    a, b, c = a + b, b - c, c * a

I will say that the fact that neither of us has an immediate use case
in mind is really the point of my previous post.  Swaps frequently
come up in sorting algorithms and heap structure modifications.
Swapping alone might be enough to justify the destructuring
assignment.

Steve
_______________________________________________
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