Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →In Python, a mutable object can change after it is created; an immutable object cannot. Assignment does not copy either kind of object: it binds a name to an object. That distinction explains why changing a list through one name affects another name for the same list, while changing a string means producing a new string value and rebinding a name.
What mutable and immutable mean
Python’s glossary defines an immutable object as “An object with a fixed value.” A mutable object, by contrast, can have its state changed in place. These terms describe objects, not the names that refer to them.
As an Amazon Associate I earn from qualifying purchases.
Common mutable built-in types include list, dict, set, and bytearray. Common immutable built-in types include str, bytes, numeric values, and tuple; frozenset is also immutable. See the Python glossary and Python data model.
Recommended Free Tools
Does assigning a list copy it?
No. Assignment creates a binding between a name and an object; it does not make an independent copy. The Python copy module documentation states: “Assignment statements in Python do not copy objects, they create bindings between a target and an object.”
#1 Best Overall
original = ["red", "blue"]
other_name = original
other_name[0] = "green"
print(original) # ['green', 'blue']
print(other_name) # ['green', 'blue']
Both names refer to the same list, so changing the list through either name is visible through the other. To test whether two references point to the identical object, use is; Python’s FAQ notes that “The is operator tests for object identity.” The printed values alone do not establish whether two names refer to the same object.
Why are Python strings immutable?
A string’s contents cannot be edited in place. Operations such as upper() or concatenation produce a string value; assigning that result to a name binds the name to the resulting value.
Rank #2
word = "python"
new_word = word.upper()
print(word) # python
print(new_word) # PYTHON
text = "cat"
text = text + "s"
print(text) # cats
The original string value remains unchanged. Python’s Design and History FAQ gives fixed storage requirements and treating strings as elemental values like numbers as reasons for string immutability; it does not provide a measured performance figure. See Why are Python strings immutable?
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsCan a tuple contain a list?
Yes. A tuple’s element references cannot be reassigned, but a referenced object can itself be mutable. That means the tuple is immutable while a list stored inside it can still change.
record = (["draft"], "notes")
record[0].append("published")
print(record) # (['draft', 'published'], 'notes')
The tuple still points to the same list in its first position; that list’s contents changed. By contrast, trying to assign a different value to record[0] raises TypeError.
Why in-place addition can still raise an error
This case is subtler:
t = (["foo"], "bar")
t[0] += ["item"]
The list’s in-place addition extends the list first. Python then attempts to assign the resulting value back into tuple slot zero, which is not allowed, and raises TypeError. The list may therefore have changed even though the full statement failed. This behavior is described in the Python Programming FAQ.
When should you copy an object?
Copy when you need independent mutation at a particular level. A shallow copy makes a new outer container but keeps references to the same contained objects. A deep copy attempts to recursively copy contained objects, according to the copy module’s behavior.
import copy
original = [[1], [2]]
shallow = copy.copy(original)
deep = copy.deepcopy(original)
original[0].append(9)
print(shallow) # [[1, 9], [2]]
print(deep) # [[1], [2]]
Here, shallow has a separate outer list but shares the inner lists, so the appended value appears through it. deep has recursively copied the nested structure in this example, so it remains unchanged. For a flat list, original.copy() is commonly enough to get a separate outer list.
Best Value
How mutability relates to hashability
Hashability determines whether an object can be used as a dictionary key or set member. A hashable object’s hash must remain stable. Lists and dictionaries are unhashable; tuples and frozensets are hashable only when their contents are hashable. So immutability alone does not guarantee hashability: a tuple containing a list cannot be used as a dictionary key.
The Python glossary explains hashability, and the data-structures tutorial explains why lists cannot serve as dictionary keys and why tuple contents matter.
Quick Recap
Quick comparison
| Question | Mutable object | Immutable object |
|---|---|---|
| Can its existing state change in place? | Yes. A list can append or replace an item. | No. A tuple cannot replace one of its element references; a string cannot have a character edited in place. |
| Does assigning it to another name make a copy? | No. Both names refer to the same object unless you explicitly copy it. | No. Assignment still binds a name; it does not copy. |
| Is it necessarily hashable? | No. Mutable containers such as lists and dictionaries are unhashable. | Not necessarily. A tuple is hashable only if all its contents are hashable. |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




