Clear variable in python

后端 未结 7 1410
猫巷女王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:53

    • If want to totally delete it use del:

      del your_variable

    • Or otherwise, to Make the value None:

      your_variable = None

    • If it's an iterable (such as a list or tuple), you can make it empty like:

      your_variable.clear()

    Then your_variable will be empty

提交回复
热议问题