Clear variable in python

后端 未结 7 1412
猫巷女王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 18:04

    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.

提交回复
热议问题