创新互联Python教程:python支持多继承吗
多继承

单继承有时候可能满足不了我们所需的所以我们就会遇到多继承,这个同样能够展示出代码的重用。
同样是上边的例子,child不仅仅是继承来自父亲,还继承来自母亲。所以我们创建mother类
class Mother(object):
def __init__(self,face):
self.face=face
print('face',face)
def play(self):
print('mother go shopping with me')mothe类创建的属性为face,其次我们还定义的一个相同的方法play 是为了展示多继承中如果有相同的函数会调用哪个。
然后我们重写一下child类
from Father import Father from Mother import Mother class Child(Mother,Father): def __init__(self,money,face): Father.__init__(self, money) Mother.__init__(self,face)
python学习网,免费的python学习网站,欢迎在线学习!
新闻标题:创新互联Python教程:python支持多继承吗
URL链接:http://www.jxjierui.cn/article/codshdp.html


咨询
建站咨询
