# 子类继承多个父类,拥有所有父类的属性和方法
class Father():
def testA(self):
print("我是father");
class Mother:
def testB(self):
print("我是mother");
class Son(Father,Mother):
def test(self):
print("我是儿子")
s=Son();
s.test();
s.testA();
s.testB()
print(Son.__mro__)
print(dir(s));
结果:

本文通过实例演示了Python中子类如何从多个父类继承属性和方法,展示了多重继承的基本用法,包括调用不同父类的方法和查看方法解析顺序。
1191

被折叠的 条评论
为什么被折叠?



