Multiple assignments

Here is a way to simoultaneously assign values to multiuple variables:

In [4]:
a, b, c = 123, 456, 789
In [5]:
a
Out[5]:
123
In [6]:
b
Out[6]:
456

Swapping variable values

Now, say we want to swap the values of a and b: to make b hold the old value of a (123), and to make a hold the old value of b (456). We can do this as follows:

In [7]:
a, b = b, a

This works: a gets assigned the old value of b, and vice-versa.

In [8]:
a
Out[8]:
456
In [9]:
b
Out[9]:
123