新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python如何重寫父類的方法
1、說明

10年積累的成都做網(wǎng)站、成都網(wǎng)站建設(shè)經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先網(wǎng)站設(shè)計后付款的網(wǎng)站建設(shè)流程,更有紅塔免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
關(guān)于父類的方法,如果不符合子類模擬的實物行為,可以重寫。因此,可以在子類中定義與重寫的父類方法同名的方法。
2、實例
import threading
import time
def catch_fish():
Pass
def one_thread():
start_time = time.time()
for i in range(1, 1001):
catch_fish()
end_time = time.time()
print("單線程測試 耗時 === %s" % str(end_time - start_time))
def muti_thread():
start_time = time.time()
for i in range(1, 1001):
threading.Thread(target=catch_fish()).start()
end_time = time.time()
print("多線程測試 耗時 === %s" % str(end_time - start_time))
if __name__ == '__main__':
# 單線程
threading.Thread(one_thread()).start()
# 多線程
muti_thread()以上就是python重寫父類的方法,希望對大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)Python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
網(wǎng)站題目:創(chuàng)新互聯(lián)Python教程:python如何重寫父類的方法
文章URL:http://fisionsoft.com.cn/article/djddooc.html


咨詢
建站咨詢
