python多重繼承實例
更新時間:2014年10月11日 15:13:28 投稿:shichen2014
這篇文章主要介紹了python多重繼承實例,簡單實用易于理解,需要的朋友可以參考下
本文實例講述了python多重繼承用法,分享給大家供大家參考。具體實現(xiàn)方法如下:
1.mro.py文件如下:
#!/usr/bin/python
# Filename:mro.py
class P1:
def foo(self):
print 'called P1-foo'
class P2:
def foo(self):
print 'called P2-foo'
def bar(self):
print 'called P2-bar'
class C1(P1, P2):
pass
class C2(P1, P2):
def bar(self):
print 'called C2-bar()'
class GC(C1, C2):
pass
2.執(zhí)行結果如下:
>>> from mro import * >>> gc = GC() >>> gc.foo() called P1-foo >>> gc.bar <bound method GC.bar of <mro.GC instance at 0xb77be2ac>> >>> gc.bar() called P2-bar >>>
3.結論:
方法解釋順序(MRO): 深度優(yōu)先, 從左至右
希望本文所述對大家的Python程序設計有所幫助。
相關文章
django+echart數(shù)據(jù)動態(tài)顯示的例子
今天小編就為大家分享一篇django+echart數(shù)據(jù)動態(tài)顯示的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08
Python時區(qū)設置方法與pytz查詢時區(qū)教程
這篇文章主要介紹了Python時區(qū)設置的方法和pytz查詢時區(qū)的方法,大家參考使用吧2013-11-11
python DES加密與解密及hex輸出和bs64格式輸出的實現(xiàn)代碼
這篇文章主要介紹了python DES加密與解密及hex輸出和bs64格式輸出的實現(xiàn)代碼,代碼簡單易懂,非常不錯對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04

