Clear variable in python

Clear variable in python

The 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

But in this case I vote for self.left = None

Whats wrong with self.left = None?

Clear variable in python

var = None clears the value, setting the value of the variable to null like value of None, however the pointer to the variable remains.

del var removes the definition for the variable totally.

In case you want to use the variable later, e.g. set a new value for it, i.e. retain the variable, None would be better.

Leave a Reply

Your email address will not be published. Required fields are marked *