Here is a way to simoultaneously assign values to multiuple variables:
a, b, c = 123, 456, 789
a
b
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:
a, b = b, a
This works: a
gets assigned the old value of b
, and vice-versa.
a
b