What you'll learn
- Create tuples with and without parentheses
- Unpack tuples
- Pick tuple vs list correctly
A tuple is an immutable list
point = (10, 20)
rgb = (255, 0, 128)
point[0] # 10
point[0] = 5 # TypeError — tuples are immutable
The bare-comma shortcut
point = 10, 20 # also a tuple — parens are optional
x, y = point # unpack into two variables
When to use a tuple
- A fixed-size pair or triple where order matters:
(lat, lon), (year, month, day).
- Returning multiple values from a function.
- As a dictionary key (lists can't be keys, tuples can).
When to use a list
- A growing/shrinking collection.
- A homogeneous "many of the same thing" (names, prices, rows).
Key takeaways
- Tuples are immutable. Use them for fixed groupings.
- Parentheses around tuples are optional in most cases.
- Tuples can be dict keys; lists cannot.
Day-of-week dict
Use tuples of (year, month, day) as keys in a dict. Add three keys with notes as values. Print one of them.
📹 Video walkthrough
A video walkthrough of this lesson will be embedded here. Until then, the
written walkthrough above mirrors what the video will cover step-for-step.