Professional Documents
Culture Documents
9.1 09 - Shared References and Mutability PDF
9.1 09 - Shared References and Mutability PDF
the same object in memory (i.e. having the same memory address)
0x1000
a = 10 a 10
b = a
b
0x1000
a = 10 a 10
b = 10
b
0x23FA
s1 = ‘hello’ s1 hello
s2 = ‘hello’
s2
1 0x1000
a = [1, 2, 3] a 2
b = a 3
b 100
b.append(100)
With mutable objects, the Python memory manager will never create shared references
1 0x1000
a = [1, 2, 3] a 2
b = [1, 2, 3] 3
1 0xF354
b 2
3