“”"
@theme 类
@time 2018/12/8
@author lz
@content _del_方法
“”"
class Cat:
def init(self,name):
self.name=name;
print(“我的 %s 名字是”% self.name)
print(1)
#在对象结束前,会自动调用_del_方法
def del(self):
print(2)
tom=Cat(“Tom”)
print(tom.name)
print("-"*50)
运行结果
“”"
@theme 类
@time 2018/12/8
@author lz
@content _del_方法
“”"
class Cat:
def init(self,name):
self.name=name;
print(“我的 %s 名字是”% self.name)
print(1)
#在对象结束前,会自动调用_del_方法
def del(self):
print(2)
tom=Cat(“Tom”)
print(tom.name)
#使用del删除对象
del tom
#因为对象删除前会自动调用_del_方法
print("-"*50)