Objects, Types, and Protocols
Reference Counting and Garbage Collection
>>> a = 37
>>> b = a # Increases reference count on 37
>>> c = []
>>> c.append(b) # Increases reference count on 37Shallow Copy vs. Deep Copy
Shallow Copy
# b is a shallow copy of a
>>> a = [1, 2, [3, 4]]
>>> b = list(a)
>>> b is a
False
# Append an element to b => a is unchanged
>>> b.append(100)
>>> b
[1, 2, [3, 4], 100]
>>> a
[1, 2, [3, 4]]
# Modify an element in b => a is changed
>>> b[2][0] = -100
>>> b
[1, 2, [-100, 4], 100]
>>> a
[1, 2, [-100, 4]]Deep Copy
First-Class Objects
Assigning Weird Things to a Dictionary
Why This is Useful
Last updated