子类中调用父类方法

可以用中文做变量

实例化和对象调用方法会自动传递self

super调用父类方法:super().__init__(name,speed),不用传self,更爱父类名补收影响

class Dad1:
    def zou(self):
        print(123)
class Son(Dad1):
    def _zou(self):
        super(Son,self).zou()
        print(456)
m=Son()
m.zou()
print(m.__class__)
子类调用父类方法示例

猜你喜欢

转载自www.cnblogs.com/jintian/p/10920733.html