Beispiel #1
0
from car2 import Car, ElectricCar
# from car2 import *
# import car2

my_car = Car("audi", "A8", 2018)
# my_car = car2.Car("audi", "A8", 2018)
print(my_car.get_descriptive_name())

my_car.odometer_reading = 30
my_car.read_odometer()

my_new_car = ElectricCar("benz", "a700", 2019)
# my_new_car = car2.ElectricCar("benz", "a700", 2019)
print(my_new_car.get_descriptive_name())
my_new_car.battery.describe_battery()
my_new_car.battery.get_range()
Beispiel #2
0
# _*_ coding :UTF-8 _*_
# 开发人员:C
# 开发时间:2019/4/30 20:13
# 文件名称:my_car.py
# 开发软件:PyCharm
from car2 import Car

my_new_car = Car('audi', 'a4', 2016)
print(my_new_car.get_descriptive_name())
my_new_car.odometer_reading = 23
my_new_car.read_odometer()
### Chapter 9: Classes

## Importing Classes

# Importing a Single Class (Cont'd)

from car2 import Car  # Imports the Car class from car2.py in the same directory

my_new_car = Car(
    'chevrolet', 'silverado',
    '2020')  # Creates new instance of Car from car2.py for my new car
print(
    my_new_car.get_descriptive_name()
)  # Calls the get_descriptive_name() method from in Car class imported from car2.py for the instance of my new car

my_new_car.odometer_reading = 23  # Sets the odometer reading of my_new_car instance of Car class imported from car2.py
my_new_car.read_odometer(
)  # Calls the read_odometer() method from Car Class imported from car2.py for the instance of my new car