Clear Variable In Python


Answer :

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


What's wrong with self.left = None?


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.


Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Change The Font Size Of Visual Studio Solution Explorer