类的继承
# 类的继承
class Car:
def __init__(self,name):
self.name = name
self.remain_miles = 0
def fill_fule(self,miles): #填充燃料
self.remain_miles = miles
def run(self,miles): #跑了多少公里
print(self.name,end=':')
if self.remain_miles > miles:
print('run %d miles'%(miles))
else:
print('fule is out!')
class GasCar(Car):
def fill_fule(self,gas): #填充燃料
self.remain_miles = gas * 6
class EleCar(Car):
def fill_fule(self,power):
self.remain_miles = power * 3
# ******** 以下是类的调用 **************
gascar = GasCar('BMW')
gascar.fill_fule(60)
gascar.run(200)
elecar = EleCar('Tesla')
elecar.fill_fule(60)
elecar.run(200)