Python多继承顺序的示例分析
这篇文章主要介绍了Python多继承顺序的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
具体如下:
示例1:
#-*- coding:utf-8 -*- #!python2 class 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): pass if __name__ == '__main__': c=C() c.caller()
运行结果:
A caller
B called
示例2:
#-*- coding:utf-8 -*- #!python2 class 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): pass if __name__ == '__main__': c=C() c.caller()
运行结果:
A caller
A called
感谢你能够认真阅读完这篇文章,希望小编分享的“Python多继承顺序的示例分析”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注行业资讯频道,更多相关知识等着你来学习!