您好,欢迎来到要发发知识网。
搜索
您的当前位置:首页python如何重写父类的方法

python如何重写父类的方法

来源:要发发知识网

1、说明

关于父类的方法,如果不符合子类模拟的实物行为,可以重写。因此,可以在子类中定义与重写的父类方法同名的方法。

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学习指路:

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

Copyright © 2019- net188.cn 版权所有 湘ICP备2022005869号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务