本帖最后由 永恒的蓝色梦想 于 2020-3-15 12:35 编辑
啊啊啊怎么说都说不清楚不如给你摆几个例子给你看就是D中super()的调用顺序
遍历__mro__,只要有一个类定义了这个方法,右边的类就不会再次尝试了>>> class a:...
>>> class b(a):...
>>> class c(a):...
>>> class d(b,c):...
>>> d.__mro__
(<class '__main__.d'>, <class '__main__.b'>, <class '__main__.c'>, <class '__main__.a'>, <class 'object'>)
>>> class a:...
>>> class b:...
>>> class c(a):...
>>> class d(b):...
>>> class e(c,d):...
>>> e.__mro__
(<class '__main__.e'>, <class '__main__.c'>, <class '__main__.a'>, <class '__main__.d'>, <class '__main__.b'>, <class 'object'>)
>>> class a:...
>>> class b(a):...
>>> class c(b):...
>>> class d(a):...
>>> class e(c,d):...
>>> e.__mro__
(<class '__main__.e'>, <class '__main__.c'>, <class '__main__.b'>, <class '__main__.d'>, <class '__main__.a'>, <class 'object'>)
|