Multiple assignment in Python is already well known.
x, y = 10, 50
But this also works when the left or right variable lists are sequences. [x,y] = 10,4
t = (1,2,3)
a,b,c = t
If you have a loop or a comprehension, and the values are sequences, you can access them like so for (left, right) in zip(leftArray,rightArray):
...
You can also do variable assignment inside an argument list. To see what I mean, suppose you're writing a 2d geometry library, and you use tuples as points. Ordinarily you might write def func(point):
x, y = point[0], point[1]
...
or even def func(point):
x, y = point
...
Instead, you can just write def func((x,y)):
...
This has many advantages. It gets around the problem of having to navigate to some other place to find out what composite data structures are. Points are just (x,y) tuples. It makes it easier to write sensible names, in many cases, which is crucial in a dynamic language. It's shorter. You spend less time packing, unpacking, and generally, schlepping your data, and more time actually doing things.Unfortunately, it's not the most generic of methods. It fixes you to a particular data representation. This is effective in certain cases, but is otherwise a problem when you need to change things. In practice, though, this can be avoided, and other code would break during such changes too.