A combo is always a drink and a size — exactly two values, never three. The toppings are a pile of unique extras with no order at all. Which container says each of those things in its shape?
Lists are not the only collection in Python. Tuples group a fixed number of values and cannot be changed. Sets store unique values and make membership tests fast. Knowing which one to reach for makes your intent clearer. You will also return fixed-shape records, use sets for membership, and compare permission sets.
Tuples are fixed records
A tuple uses parentheses and keeps its values in order. You can read by index or unpack it into named variables. A tuple itself cannot be changed after creation, which makes it useful for a coordinate, a pair, or a record that should stay fixed.
point = (3, 5)
x, y = point
print(x + y)Unpacking a tuple
Sets keep unique values
A set removes duplicates and does not promise a display order. Use it when uniqueness or membership matters more than position. Converting a list to a set is a quick way to count distinct values.
orders = ["latte", "tea", "latte"]
unique = set(orders)
print(len(unique))
print("tea" in unique)Deduplication and membership
Set operations
The ampersand finds values in both sets; the pipe finds values in either set. Sort the result when you need a stable display order. Do not rely on the raw order of a set in output.
a = {1, 2, 3}
b = {3, 4}
print(sorted(a & b))
print(sorted(a | b))Intersection and union
A tuple is a shape, not a short list
Use a tuple when the number of fields is part of the meaning. divmod() returns a quotient and remainder; unpacking names both at once. A starred target collects the rest, which is useful for a header plus a variable-length tail.
quotient, remainder = divmod(17, 5)
print(quotient, remainder)
record = ("2026-10-28", "latte", 4.5, "paid")
date, drink, *rest = record
print(date, drink)
print(rest)Unpack by position when the shape is fixed
Membership is the question a set answers
A set removes duplicates and answers in quickly. It does not promise insertion order, so sort before display. Keep a list when history or duplicates matter; convert to a set only when uniqueness is the goal.
visits = ["home", "menu", "home", "checkout"]
unique_pages = set(visits)
print(len(unique_pages))
print(sorted(unique_pages))
print("menu" in unique_pages)
print("help" in unique_pages)Unique values, not a timeline
Compare permissions with subset and difference
Set operators express access rules. required <= granted asks whether every required permission is present. granted - required lists extras, while required - granted lists gaps. A non-empty intersection is weaker than a subset test.
required = {"read", "write"}
granted = {"read", "write", "admin"}
print(required <= granted)
print(sorted(granted - required))
print(sorted(required - granted))
print(sorted(required ^ granted))Subset asks whether access is complete
Key points
- Tuples preserve order and cannot be modified in place.
- Tuple unpacking assigns each value to a named variable.
- Sets remove duplicates and support fast membership checks.
- Sort a set before printing when order matters.
- Use a tuple for a fixed record and a set for uniqueness or membership.
Common mistakes
- Trying to append to a tuple instead of creating a new tuple.
- Expecting a set to preserve the original list order.
- Using a list when the important question is whether a value exists.
- Testing only the intersection when every required permission must be present.
Create a tuple with a name and price, unpack it, and print a formatted sentence.
Try it yourself
Change the values, predict the output, then run the code. The Python runtime is downloaded the first time you press Run, so the first run can take a few seconds.
Practice this lesson
12 questions with immediate explanations.