Given the root of a binary tree, for instance below, I am running the following tests in Python:
1 / \ 2 5 / \ 3 4
cur = root root = None print(root, cur) None, node 1
cur = root root.left = None print(root.left, cur.left) None, None
In both tests cur and root point to the same memory location. In test 1, why changing root to None did not modify cur? But in test 2 when I assign root.left to None, cur.left is also changed?