A mutable object is one whose value can be changed in place after creation. In Python, the core mutable types include list, dict, set, and bytearray. When you append to a list, add a key to a dictionary, or update a set, you are modifying the existing object rather than creating a new one. This means all names referring to that object see the change immediately — a phenomenon called aliasing.
Mutability is powerful but requires care. The classic beginner trap is using a mutable default argument in a function definition: def f(items=[]). Because the default list is created once at function definition time and reused across calls, mutations accumulate unexpectedly. The standard fix is to use None as the default and create a new list inside the function.
Mutable objects generally cannot be used as dictionary keys or set elements because their hash could change if their contents change. The distinction between mutable and immutable types is one of the most important concepts in Python. It affects assignment semantics, function argument passing (Python passes object references, not values or pointers), copy behaviour (shallow vs deep copies), and thread safety.
Related terms: Immutable, List, Dictionary, Set
Discussed in:
- Chapter 3: Variables and Data Types — Names, Not Boxes