本文實例講述了Python多繼承順序。分享給大家供大家參考,具體如下:
示例1:
#-*- coding:utf-8 -*-#!python2class A(object): def caller(self): print 'A caller' self.called() def called(self): print 'A called'class B(object): def called(self): print 'B called'class C(B,A): passif __name__ == '__main__': c=C() c.caller()
運行結果:
A caller
B called
示例2:
#-*- coding:utf-8 -*-#!python2class A(object): def caller(self): print 'A caller' self.called() def called(self): print 'A called'class B(object): def called(self): print 'B called'class C(A,B): passif __name__ == '__main__': c=C() c.caller()
運行結果:
A caller
A called
更多關于Python相關內容感興趣的讀者可查看本站專題:《Python面向對象程序設計入門與進階教程》、《Python數據結構與算法教程》、《Python Socket編程技巧總結》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python編碼操作技巧總結》及《Python入門與進階經典教程》
希望本文所述對大家Python程序設計有所幫助。
新聞熱點
疑難解答