zoukankan      html  css  js  c++  java
  • python 多继承的实现

    第一类多继承的实现
    from Child import Child
    def main():
    c = Child(300, 100)
    print(c.money, c.faceValue)
    c.play()
    c.eat()
    #注意:父类中方法名相同,默认调用的是在括号中排前面的父类中的方法
    c.func()
    if __name__ == "__main__":
    main()

    第二类Mother
    class Mother(object):
    def __init__(self, faceValue):
    self.faceValue = faceValue
    def eat(self):
    print("eat")
    def func(self):
    print("func2")

    第三类Father
    class Father(object):
    def __init__(self, money):
    self.money = money
    def play(self):
    print("play")
    def func(self):
    print("func1")

    第四类Child
    from Father import Father
    from Mother import Mother

    class Child(Father, Mother):
    def __init__(self, money, faceValue):
    #写法
    Father.__init__(self, money)
    Mother.__init__(self, faceValue)
  • 相关阅读:
    第06组Alpha冲刺(4/6)
    第06组Alpha冲刺(3/6)
    第06组Alpha冲刺(2/6)
    第06组 Alpha冲刺 (1/6)
    08-js函数
    07-数组
    06-js分支
    05-js运算符
    04-js变量
    03-css3D转换
  • 原文地址:https://www.cnblogs.com/pygo/p/12306867.html
Copyright © 2011-2022 走看看