子类对父类的调用,主要是参数和方法调用
#子类调用父类的方法 class Vehichle: Country='china' #名字='ales'不好这样 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(Vehichle):#要有自己的心的参,其他全继承 def __init__(self,name,speed,load,power,line): # self.name = name # self.speed = speed # self.load = load # self.power = power Vehichle.__init__(self,name,speed,load,power) #self作为具体的实例内容 # 子类的调用父类的参数名直接调用,也要加上self self.line=line def showinfo(self): print(self.name,self.line) def run(self): Vehichle.run(self)#子类调用父类的方法,self必须加上 print('%s开动了'%self.name) line1=Subway('1号线','2km/h','23412人','电',12) line1.showinfo() line1.run()