示例#1
0
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!')
 def __init__(self,make,model,year):
     """初始化父类的属性,再初始化电动汽车特有的属性"""
     # super(ElectricCar, self).__init__(make,model,year)
     super().__init__(make,model,year)
     #super() 是一个特殊函数,帮助Python将父类和子类关联起来
     self.battery = Battery(85)
示例#3
0
 def __init__(self, make, model, year):
     super().__init__(make, model, year)
     self.battery = Battery(70)
     self.__some_variable = 10
示例#4
0
 def __init__(self, make, model, year):
     super().__init__(make, model, year);
     self.battery = Battery()
示例#5
0
"""import classes to the main program"""
from car import Car
from car import ElectricCar
from car import Battery
"""Uses instances and objects in Car"""
my_car=Car('b m w','320i',2008)
print(my_car.description())
print(my_car.make.title())
"""Uses instances and objects in ElectricCar"""
my_volks=ElectricCar('audi','r8',2018)
my_volks.des_batt()
print(my_volks.model.title())
"""Uses instances and objects in Battery"""
my_tesla=Battery('tesla','model s',2018,'Lithian')
my_tesla.des_battery()
print(my_tesla.model.title())
示例#6
0
from car import Car, ElectricCar
my_beetle = Car('volkswagen', 'beetle', 2019)
print(my_beetle.get_descriptive_name())
my_tesla = ElectricCar('tesla', 'roadster', 2019)
print(my_tesla.get_descriptive_name())

import car
my_beetle = car.Car('volkswagen', 'beetle', 2019)
print(my_beetle.get_descriptive_name())
my_tesla = car.ElectricCar('tesla', 'roadster', 2019)
print(my_tesla.get_descriptive_name())

from car import Battery
battery1 = Battery(17)
battery1.describe_battery()
battery1.upgrade_battery()
battery1.get_range()
battery1.describe_battery()
battery1 = Battery(18)
battery1.describe_battery()
示例#7
0
 def __init__(self, make, model, year):
     # Initialize attributes of the parent class
     super().__init__(make, model, year)
     self.battery = Battery()