python 多继承优先级__mro__
如果类C 继承自类A类B,且AB中都有函数f
则调用c.f时根据继承的先后顺序确定调用哪个类中的f
class A( ):
def f(self):
print("A卖茶叶蛋...")
class B( ):
def f(self):
print("B卖茶叶蛋...")
class C( B,A):
def __init__(self):
self.kongfu = '[阿松大]'
c = C()
c.f() #调用A中的,因为class C( A,B):A在B前
print(C.__mro__)#使用mro可获得多继承优先级
-
-
MRO 是
method resolution order
, 主要用于在多继承时判断 方法 属性的 调用顺序