I am trying to understand python behavior. I have the piece of code below: (TreeNode is a normal binary tree class)
class Solution:
def anotherfunction(self, root, key):
print(root)
if(root.val == key):
root = None
print(root)
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
self.anotherfunction(root, key)
print(root)
The output is as shown below:
TreeNode{val: 5, left: TreeNode{val: 2, left: None, right: None}, right: None}
None
TreeNode{val: 5, left: TreeNode{val: 2, left: None, right: None}, right: None}
I don't know why the root in my delete node function is not getting modified? I am new to Python3 and in C++ if I just pass the root using *& it works fine. I want to know what is the python equivalent of passing by reference?