Tuple vs List Mutability
Run the Tuple vs List Mutability MicroSim Fullscreen
Edit in the p5.js Editor
About This MicroSim
This MicroSim compares the same operation on two Python data structures that start with identical values:
- Mutable list: [1, 2, 3]
- Immutable tuple: (1, 2, 3)
Students click operation buttons and immediately see the contrast: - The list updates successfully. - The tuple remains unchanged and displays the Python error type.
How to Use
- Click
Change Itemto attempt index assignment on both structures. - Click
Add Itemto attempt append on both structures. - Click
Remove Itemto attempt removing the last item on both structures. - Observe green success feedback on the list and red error feedback on the tuple.
- Click
Resetto restore both to their original state.
Iframe Embed Code
1 2 3 4 | |
Lesson Plan
Grade Level
9-12 (High School Computer Science)
Duration
10-15 minutes
Prerequisites
- Basic Python syntax
- Understanding of variables and sequence indexing
Activities
- Prediction (3 min): Students predict which operations work on list and tuple.
- Exploration (6 min): Students run each operation and record observed outcomes.
- Explain (4 min): Students explain why tuple operations fail using the term "immutable."
- Extension (2 min): Students propose when tuples are preferable to lists.
Assessment
- Student can explain mutability vs immutability in plain language.
- Student correctly identifies list operations that mutate values.
- Student recognizes tuple operation failures and names the error category.
References
- Python Tutorial: Data Structures (lists): https://docs.python.org/3/tutorial/datastructures.html
- Python Standard Types (tuples): https://docs.python.org/3/library/stdtypes.html#tuple