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('开动啦') print('开动啦') class Subway(Vehicle): def __init__(self,name,speed,load,power,line): Vehicle.__init__(self,name,speed,load,power)#相当于把父类初始化函数全部复制过来 self.line=line def show_info(self):#派生的 print(self.name,self.speed,self.load,self.power,self.line) def run(self): Vehicle.run(self) print('%s %s 线,开动啦' %(self.name,self.line)) line13=Subway('北京地铁','10km/s',1000000000,'电',13) # line13.show_info() line13.run()
北京地铁 10km/s 1000000000 电 13
开动啦开动啦北京地铁 13 线,开动啦