首页 > 其他 > 详细

多继承

时间:2019-08-13 14:52:31      阅读:65      评论:0      收藏:0      [点我收藏+]
 1 class A:
 2     def test(self):
 3         print("A --- test方法")
 4 
 5     def demo(self):
 6         print("A --- demo方法")
 7 
 8 class B:
 9     def test(self):
10         print("B --- test方法")
11 
12     def demo(self):
13         print("B --- demo方法")
14 
15 
16 class C(A,B):
17     pass
18 
19 
20 c = C()
21 print(dir(c)) #dir()显示该类中所有的方法和属性
22 c.test()
23 c.demo()
24 print(C.__mro__)  #向上查询顺序
[‘__class__‘, ‘__delattr__‘, ‘__dict__‘, ‘__dir__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__gt__‘, ‘__hash__‘, ‘__init__‘, ‘__le__‘, ‘__lt__‘, ‘__module__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__setattr__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘__weakref__‘, ‘demo‘, ‘test‘]
A --- test方法
A --- demo方法
(<class ‘__main__.C‘>, <class ‘__main__.A‘>, <class ‘__main__.B‘>, <class ‘object‘>)

  

多继承

原文:https://www.cnblogs.com/yifengs/p/11345754.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!