1. 程式人生 > >機器學習之python基礎篇

機器學習之python基礎篇

“”"
@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)
在這裡插入圖片描述