千家信息网

Python-7 多继承函数调用注意点

发表于:2025-02-03 作者:千家信息网编辑
千家信息网最后更新 2025年02月03日,例:class Base(object):def test(self):print("---------Base")class A(Base):def test(self):print("------
千家信息网最后更新 2025年02月03日Python-7 多继承函数调用注意点

例:

class Base(object):
def test(self):
print("---------Base")

class A(Base):
def test(self):
print("---------A")

class B(Base):
def test(self):
print("---------B")

class C(A,B):
def test(self):
print("---------C")

c = C()
c.test() #此处所有的类中都有test()方法,是以什么顺序调用?

print(c._ mro _) #通过此方法可打印出方法调用优先级

#在所有类中尽量避免有相同的方法名

0