Tuples and Unpacking
Tuples are immutable sequences. Unpack into names, use * to gather the rest and swap without a temporary.
Example
t = (1, 2, 3, 4)
a, *mid, z = t
print(a, mid, z)
x, y = 1, 2
x, y = y, x
print(x, y)Result
1 [2, 3] 4 2 1
Exercise
Gather the rest.
a, rest = t
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.