Python Tuples and Immutability
Objective 3.2 is short because a tuple is a list you cannot change - the indexing and slicing from the previous guides applies unaltered. What is worth the time is everything around that: (1) is not a tuple and 1, is, immutability does not reach inside the items, and the reason a tuple can be a dictionary key while a list cannot is the single idea the whole objective is built on.
Data Collections Guide 15 of 26 Beginner
- OSUbuntu 26.04 LTS
- Python3.14.4
- pip25.1.1
- TimeAbout 15 min
Unchanged in Python 3. Starred unpacking - first, *rest = t - arrived in Python 3.0 and is not on the PCEP syllabus, but it is shown here because it appears in real code and in some practice questions.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Python 3.14.4 - the only machine this path needs | 2 Core | 4 GB | 50 GB |
This guide includes
Use this for the tuple objective. This matters because the comma makes the tuple rather than the brackets - and immutable stops at the tuple itself, never reaching the objects inside it.
- doing everything a list can do, minus changing
- finding that the comma makes the tuple, not the brackets
- meeting three ways a tuple refuses, with three different exceptions
- seeing that immutability does not reach inside the items, and that a tuple has exactly two methods
- unpacking, swapping, and learning why a tuple can be a dictionary key
Before you start
-
Everything a list can do, minus changing
-
The comma makes the tuple, not the brackets
-
Three ways a tuple refuses, three different exceptions
-
Immutable does not reach inside the items
-
A tuple has exactly two methods
-
Unpacking, and the swap it makes possible
-
When unpacking does not fit
-
Why a tuple can be a dictionary key
-
What the exam does with this objective