Python lists: alias vs copy

a = [1, 2, 3]
b = a          # alias — same object
c = a.copy()  # copy — new object
Alias (same memory)
Copy (different memory)
Changed cell
a →
0x1A2B
1
2
3
b →
0x1A2B
1
2
3
← same object as a
c →
0x3C4D
1
2
3
← independent copy
Click a button above to mutate a list and see what changes.
a = [[1,2], [3,4], [5,6]]
b = a.copy()    # outer list is a new object…
                # but inner lists are still shared!
Alias (shared inner list)
New outer list
Changed cell
a →
outer list 0xAA11 (original)
1
2
3
4
5
6
inner lists = aliases
b →
outer list 0xBB22 (copy) ← new object!
1
2
3
4
5
6
Click any inner sub-list to mutate its first element — see if the change appears in both a and b.
Click a nested sub-list above to mutate it.
# Fix: use deepcopy to copy all levels
import copy
b = copy.deepcopy(a)  # now inner lists are truly independent
import copy
a = [[1,2], [3,4], [5,6]]
c = copy.deepcopy(a)  # ALL levels are new independent objects
Truly independent (deep copy)
Changed cell
Unchanged
a →
outer list 0xAA11 — inner lists 0xA1, 0xA2, 0xA3
1
2
3
4
5
6
✓ no shared references — inner lists are fully independent
c →
outer list 0xCC33 — inner lists 0xC1, 0xC2, 0xC3 (all new!)
1
2
3
4
5
6
Click any inner sub-list to mutate it — only that variable's list changes.
Click a nested sub-list above to mutate it.
How it works under the hood
deepcopy() walks the entire object graph recursively. Every inner list — and every object inside those lists — is allocated as a brand-new object with its own memory address. After a deepcopy, there is no shared state between a and c at any level.
# Verify with id() — every address is different
id(a) == id(c)     # False — new outer list
id(a[0]) == id(c[0]) # False — new inner lists too!
One caveat
deepcopy() is slower and uses more memory — it copies everything recursively. If your inner lists only contain immutable items (integers, strings, tuples), a shallow .copy() is always safe because immutables can't be mutated anyway.