from car import ElectricCar

tesla = ElectricCar("Tesla", "S4", "2018")
print(tesla.describe_car())
tesla.describe_battery()
Exemple #2
0
from car import ElectricCar

my_tesla = ElectricCar('tesla', 'model s', 2019)
print(my_tesla.get_descriptive_name())
my_tesla.describe_battery()
my_tesla.battery.get_range()
my_tesla.battery.upgrade_battery()
my_tesla.battery.get_range()


Exemple #3
0
        if self.battery_size == 75:
            return 260
        if self.battery_size == 100:
            return 315

class ElectricCar(Car):
    '''doc, blabla...'''

    def __init__(self, make, model, year):
        super().__init__(make, model, year);
        self.battery = Battery()

    def describe_battery(self):
        self.battery.describe_battery()

    # 重载函数
    def fill_gas_tank(self):
        print('No gas tank for elactric car!')

electric_car = ElectricCar('Tesla', 'Model Y', 2021)
print(f'ecar: {electric_car.descriptive_name()}')
electric_car.describe_battery()

#%% 方法重载
electric_car.fill_gas_tank()

#%% 
from car import Car, ElectricCar, Battery
from car import ElectricCar as Ecar