Answers for "delete objects and variables in destructr python"

2

python class destructors

#Class
class animal:
  #Constructor
  def __init__(self,name):
    self.name = name
	print(name+" has been born!")
  #Deconstructor
  def __del__(self)
  	print(self.name+" has died D:")

ben = animal("Ben")

del ben

#Output:
#Ben has been born!
#Ben has died D:
Posted by: Guest on March-10-2020

Code answers related to "delete objects and variables in destructr python"

Python Answers by Framework

Browse Popular Code Answers by Language