Clear variable in python

后端 未结 7 1423
猫巷女王i
猫巷女王i 2020-12-22 17:16

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
            


        
7条回答
  •  清歌不尽
    2020-12-22 17:52

    The del keyword would do.

    >>> a=1
    >>> a
    1
    >>> del a
    >>> a
    Traceback (most recent call last):
      File "", line 1, in 
    NameError: name 'a' is not defined
    

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

提交回复
热议问题