1、说明
关于父类的方法,如果不符合子类模拟的实物行为,可以重写。因此,可以在子类中定义与重写的父类方法同名的方法。
2、实例
importthreading importtime defcatch_fish(): Pass defone_thread(): start_time=time.time() foriinrange(1,1001): catch_fish() end_time=time.time() print("单线程测试耗时===%s"%str(end_time-start_time)) defmuti_thread(): start_time=time.time() foriinrange(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学习指路:Python基础教程
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)