Tuples and unpacking

A tuple is like a list that can't change: point = (3, 4). Trying point[0] = 10 raises TypeError. Use a tuple for a fixed group of values, such as a coordinate or a row.

The comma makes the tuple, not the parentheses. (5,) is a tuple with one item, but (5) is just the number 5.

Unpacking assigns each item to its own name: x, y = point. A starred name collects the rest into a list: first, *rest = [1, 2, 3, 4].

Unpacking is why Python can return "several values". A function returns one tuple, and the caller unpacks it: low, high = min_max(values). It also gives you the one-line swap a, b = b, a, which interviewers like to see.

If the counts don't match, as in x, y = (1, 2, 3), you get ValueError.

Run it, then try *start, last = "hello".