class Car():
def __init__(self,make,model,year):
self.make=make
self.model=model
self.year=year
self.odometer_reading = 0
def get_descriptive_name(self):
print(self.make+" "+self.model+" "+str(self.year))
def read_odometer(self):
print("This car has "+self.odometer_reading+" mails on it.")
class Battery():
def __init__(self,battery_size=70):
self.battery_size=battery_size
def describe_battery(self):
print("The car has "+str(self.battery_size)+" -kWh battery.")
class ElectricCar(Car):
def __init__(self,make,model,year):
super().__init__(make,model,year)
self.battery=Battery()
my_new_car=ElectricCar('we','vee',2013)
print(my_new_car.get_descriptive_name())
my_new_car.battery.describe_battery()
所以结果会多一个None
|