Python多继承
多继承的格式形同单继承,如:
class C (A,B)
其中,A,B类均为父类
class A:
def test(self):
print("test方法")
class B:
def demo(self):
print("demo方法")
class C (A,B):
pass
c = C()
c.test()
c.demo()
多继承的使用注意事项,当父类中有同名的属性或者方法时
class A:
def test(self):
print("A类的test方法")
class B:
def test(self):
print("B类的test方法")
class C(A,B):
pass
class D (B,A):
pass
c = C()
print("C类")
c.test()
d = D()
print("D类")
d.test()
在定义多继承时,具有同名方法的类中,会调用先继承的方法