So, i just done my little experiment.
In the following Python code:
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
a = []
b = TreeNode(1)
a.append(b)
b = None
print(id(a[0]) # 140103806472096
print(id(b)) # 9520032
The first print gives different id than the second. What is happening to both a[0] and b after I assign None type to b? If the append() adds a reference to the list instead a copy as said here, why would these two ids differ and a[0] still stores the original TreeNode?