Ejemplo 1: destructores de clases de Python
#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:
Ejemplo 2: destrucción de clases de Python
class animal:
def __init__(self,name):
self.Name = name
def __del__(self):
print(self.Name+" has died D:")
ben = animal("Ben")
def deleteObj(obj):
del obj
deleteObj(ben)
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)