A8PythonBeginnerAbout 90 min to complete
Tuples
Understanding why immutability is a feature — and where tuples are not merely allowed but required.
Notebook
About 90 minutes to complete
Enrol to read the notebook and download it to run.
What this module covers
Understanding why immutability is a feature — and where tuples are not merely allowed but required.
By the end of it
- Create tuples correctly, including the single-element case that catches everyone
- Explain immutability precisely — including why a tuple containing a list is still mutable
- Unpack tuples fluently, including starred and nested unpacking
- Return multiple values from a function and understand that it is a tuple underneath
- Explain hashability, and use tuples as dictionary keys and set members
- Use namedtuple and typing.NamedTuple to build readable, self-documenting records
- Compare tuples to lists on memory, speed, and intent, and choose deliberately
- Recognise where pandas uses tuples: MultiIndex, .shape, .itertuples()