Example #1
0
my_new_car.odomter_reading = 3
my_new_car.read_odomeer()

my_new_car.update_odometer(10)
my_new_car.read_odomeer()

my_new_car.update_odometer(5)
my_new_car.read_odomeer()

my_new_car.update_odometer(23500)
print(my_new_car.odomter_reading)

my_new_car.increment_odometer(100)
print(my_new_car.odomter_reading)

padding()

my_tesla = Car.ElectricCar('tesla', 'roadster', 2016)
print(my_tesla.get_descriptive_name())

padding()

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() + ".")
Example #2
0
# 导入模块中的类
# ~ from Car import Car, ElectricCar

# ~ my_new_car = Car('audi', 'a6', 2016)
# ~ print(my_new_car.get_description_name())

# ~ my_new_electric_car = ElectricCar('telsa', 's', 2016)
# ~ print(my_new_electric_car.get_description_name())
# ~ my_new_electric_car.battery.description_battery()

# 导入整个模块
import Car
my_new_car = Car.Car('audi', 'a6', 2016)
print(my_new_car.get_description_name())

my_new_electric_car = Car.ElectricCar('telsa', 's', 2016)
print(my_new_electric_car.get_description_name())
my_new_electric_car.battery.description_battery()
Example #3
0
import Car
my_tesla = Car.ElectricCar('tesla', 'model s', 2016)
print(my_tesla.get_descriptive_name())
Example #4
0
#python类的创建和使用
import Pepole as p
import Car as c
import User as u
p1 = p.Pepole('zzl', 28, 'China')
#python链式编程:返回self即可
print(
    p1.change_name('zzl_001').change_nation('England').append_age(
        4).append_age(-9).get_personal_info())
print('========继承===========')
ec = c.ElectricCar('i5', 'bmw', 2007, 1000000)
ec.description()
ec.set_year(2020).increase_distance(30)
ec.description()
ec.increase_oil(0)
ec.battery.charge(50)
ec.display()
ec.battery.charge(200)
ec.battery.get_range()
print('========================')
test_user = u.AdminUser('zzl', '123456')
u_name = input('请输入用户名:\n')
u_pwd = input('请输入密码:\n')
login_result = test_user.login(u_name, u_pwd)
if login_result == None:
    print('登录失败')
else:
    print('登录成功')
print('===========')
print('拥有的权限有:')
for v in test_user.privileges: