class a(object):
def __init__(self):
print('in a')
class b(a):
def __init__(self):
print('in b')
super().__init__()
print('out b')
class c(a):
def __init__(self):
print('in c')
super().__init__()
print('out c') class d(b, c):
def __init__(self):
print('in d')
super().__init__()
print('out d') a = d()
print(a.__class__.mro())

每个对象都有个属性__class__.mro()

mro是method resolve order的缩写

代码中是写的super().__init__()

super()这种写法是super(当前类名,self)的简写

然后我们直接来看看这段代码执行的结果

[Running] python "d:\pyqt5\signal.py"
in d
in b
in c
in a
out c
out b
out d
(<class '__main__.d'>, <class '__main__.b'>, <class '__main__.c'>, <class '__main__.a'>, <class 'object'>)

为啥中间会输出c?

c并不是b的父类啊

super其实干的是下面这件事

def super(cls, inst):
mro = inst.__class__.mro()
return mro[mro.index(cls) + 1]

就是在mro列表中去找下一个类,所以会产生这种输出

最新文章

  1. 纯html页面之间传参
  2. Swift:属性观察器
  3. 开发Windows Phone应用程序之后的感觉
  4. dg
  5. css教程
  6. openstack简介
  7. JSP&amp;Servlet学习手册
  8. Spring MVC 时间字符串 @PathVariable获取
  9. servlet其工作原理和例子证明
  10. JavaScript 中 if 条件判断
  11. 简单说下C#变量的作用域
  12. IT女孩特不烦恼---九月实习总结
  13. vue-These relative modules were not found
  14. BZOJ 4282(慎二的随机数列
  15. 【读书笔记】iOS-基带攻击
  16. vs远程调试 转http://www.cnblogs.com/magicchaiy/archive/2013/05/28/3088274.html
  17. jupyter notebook的路径
  18. [设备]Linux设备是否可以被多个进程或者线程同时Open?
  19. ctex2.9.2输出中文
  20. MetaPost使用

热门文章

  1. MongoDB 学习笔记之 检测存储引擎
  2. java架构之路-(分布式zookeeper)zookeeper真实使用场景
  3. MyBatis拦截器自定义分页插件实现
  4. Switch-case语句的应用
  5. Linux之常用命令I
  6. 不就是SELECT COUNT语句吗,竟然能被面试官虐的体无完肤
  7. Windows API 编程入门
  8. PHP会话机制---session的基本使用
  9. shark恒破解笔记1-壳内寻找注册码
  10. PHP array_replace