-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_car.py
54 lines (26 loc) · 1.01 KB
/
my_car.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'''导入类'''
# 导入多个类
from Chapter9_Class import Car, ElectricCar
# from Chapter9_Class import ElectricCar
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()
my_tesla = ElectricCar('tesla', 'model s', 2016)
print(my_tesla.describe_battery())
my_tesla.battery.describe_battery()
my_tesla.battery.get_range()
#导入整个模块
import Chapter9_Class
my_beetle = Chapter9_Class.Car('volkswagen', 'beetle', 2016)
#导入模块中的所有类 不推荐这种方式 使用是用module_name.class_name语法访问类
from Chapter9_Class import *
#python标准库
from collections import OrderedDict
favorite_languages = OrderedDict()
favorite_languages['jen'] = 'python'
favorite_languages['sarah'] = 'c'
favorite_languages['edward'] = 'ruby'
favorite_languages['phil'] = 'python'
for name, language in favorite_languages.items():
print(name.title() + "'s favorite language is " + language.title() + ".")