Packing and unpacking
The tuple packs two values; unpacking copies them into x and y. Indexing and len() work exactly as they do on lists.
point = (3, 4)
x, y = point
print(x + y)
print(len(point), point[0])7 2 3
Python Programming · Lesson 2.6.2
Fixed collections that cannot change after creation — packing values together, unpacking them back, and when a tuple beats a list.
A tuple is a sequence like a list, written with round brackets: point = (3, 4). It stores elements in order and supports indexing and slicing exactly like a list. The one difference is huge: tuples are immutable — once created, you can never change, add or remove an element. Try point[0] = 9 and Python raises TypeError: 'tuple' object does not support item assignment. Read that message carefully; it appears in MCQs almost word for word. Everything you already know about reading lists transfers to tuples unchanged.
Why does Python need an unchangeable sequence? Fixed records: a coordinate pair, an RGB colour, a roll-number–name–marks row. When a value must not drift — a date of birth, an answer key — a tuple guarantees it. Immutability also lets tuples be used as dictionary keys, which lists cannot. In team projects, handing a function a tuple is a promise: you may read this, but not edit it. That promise prevents a whole family of accidental bugs.
Packing writes several values into one tuple: position = 25, 40 packs even without brackets. Unpacking pulls them back out into separate variables: x, y = position — the right side must supply exactly as many values as there are names, or Python raises ValueError. The star of the show is the swap: a, b = b, a exchanges two variables in one line with no temporary variable, because the right side is fully evaluated before any assignment happens.
One-element tuples need a trailing comma: single = (5,) is a tuple of length 1, while (5) is just the number 5 in brackets. Print single and Python confirms it with (5,). Forgetting that comma is a classic quiz question. Also remember that len(), indexing and in all work on tuples, so most list-reading code runs on tuples without edits — only the changing operations are missing.
Choosing rule of thumb for the board exam: use a list for a collection that grows or gets edited (marks that update, a to-do queue); use a tuple for a fixed record whose parts belong together (coordinates, a date, two answers returned together). If a question asks which structure and why, state the mutability difference first, then give the reason — that two-step answer earns full marks.
The tuple packs two values; unpacking copies them into x and y. Indexing and len() work exactly as they do on lists.
point = (3, 4)
x, y = point
print(x + y)
print(len(point), point[0])7 2 3
The right side (b, a) is built first and then assigned, so the swap needs no temporary variable. Unpacking must match the value count exactly.
a, b = 10, 20
a, b = b, a
print(a, b)
position = (25, 40, 55)
rolls, marks, rank = position
print(marks, rank)20 10 40 55
Without the comma the brackets are plain grouping — (5) is the int 5. The trailing comma is what makes it a tuple.
single = (5,)
print(single, len(single))
not_a_tuple = (5)
print(not_a_tuple)(5,) 1 5
An ordered, immutable sequence written with parentheses, like (3, 4).
Cannot be changed after creation; tuple elements can never be reassigned.
Collecting several values into one tuple, e.g. position = 25, 40.
Splitting a tuple into separate named variables, e.g. x, y = position.
Exchanging two variables' values in one step with a, b = b, a.
Common mistake
Tuples are just lists written with ( ) instead of [ ].
Correct understanding
The brackets differ, but the real difference is immutability: a tuple can never be edited, appended to or shrunk after creation.
Common mistake
(5) creates a tuple containing 5.
Correct understanding
(5) is just the number 5 — brackets alone group. The tuple needs a trailing comma: (5,).
Common mistake
x, y = point works as long as point has at least two elements.
Correct understanding
The counts must match exactly — three values into two names raises ValueError: too many values to unpack.