Is there a way to clear the value of a variable in python?
For example if I was implementing a binary tree:
Class Node: self.left = somenode1 self.right = somenode2
If I wanted to remove some node from the tree, I would need to set
self.left to empty.
What's wrong with
self.left = None?
del keyword would do.
>>> a=1 >>> a 1 >>> del a >>> a Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'a' is not defined
EDITED: But in this case I vote for
self.left = None