![图片[1]-python支持多继承吗-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5df97ec6b14e4138.gif)
多继承
单继承有时候可能满足不了我们所需的所以我们就会遇到多继承,这个同样能够展示出代码的重用。
同样是上边的例子,child不仅仅是继承来自父亲,还继承来自母亲。所以我们创建mother类
classMother(object):
def__init__(self,face):
self.face=face
print('face',face)
defplay(self):
print('mothergoshoppingwithme')
mothe类创建的属性为face,其次我们还定义的一个相同的方法play 是为了展示多继承中如果有相同的函数会调用哪个。
然后我们重写一下child类
fromFatherimportFather fromMotherimportMother classChild(Mother,Father): def__init__(self,money,face): Father.__init__(self,money) Mother.__init__(self,face)原文来自:https://www.py.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
















































暂无评论内容