12.Python3子类调用父类的方法

class Vehicle:
    
    Country = "China"

    def __init__(self,name,speed,load,power):
        self.name  = name
        self.speed = speed
        self.load  = load
        self.power = power

    def run(self):
        print("开动啦...")


class Subway(Vehicle):

    def __init__(self,name,speed,load,power,line):
        self.line = line
        # Vehicle.__init__(self,name,speed,load,power)
        # super(Subway,self).__init__(name,speed,load,power)
        super().__init__(name,speed,load,power)

    def run(self):
        # Vehicle.run(self)
        super().run()
        print("%s第%s号线,开动啦..."%(self.name,self.line))


s1 = Subway("成都地铁","1000km/s",2000,'蒸汽&电',740)
s1.run()

你可能感兴趣的:(12.Python3子类调用父类的方法)