标签:字母 odi get mode int title read update bsp
cat car.py
1 #! /usr/bin/python 2 # -*- coding:utf-8 -*- 3 4 5 class Car(object): 6 """ 7 模拟汽车 8 """ 9 def __init__(self, make, model, year): 10 """初始化汽车的属性""" 11 self.make = make 12 self.model = model 13 self.year = year 14 self.odometer_reading = 0 15 16 def get_descriptive_name(self): 17 """ 18 返回描述性名称 首字母大写 19 :return: 20 """ 21 long_name = str(self.year) + ‘ ‘ + self.make + ‘ ‘ + self.model 22 return long_name.title() 23 24 def read_odometer(self): 25 """ 26 打印汽车的里程 27 :return: 28 """ 29 print "This car has " + str(self.odometer_reading) + " miles on it." 30 31 def update_odometer(self, mileage): 32 """ 33 将里程表读数设置为指定的值 34 拒绝将里程表往回拨 35 :param mileage: 36 :return: 37 """ 38 if mileage >= self.odometer_reading: 39 self.odometer_reading = mileage 40 else: 41 print "You can‘t roll back an odometer!" 42 43 def increment_odometer(self, miles): 44 """ 45 将里程表读数增加指定的量 46 :param miles: 47 :return: 48 """ 49 self.odometer_reading += miles 50 51 def full_gas_tank(self): 52 """油箱""" 53 print "汽车有邮箱"
标签:字母 odi get mode int title read update bsp
原文地址:https://www.cnblogs.com/leejay/p/14409727.html