Python继承

#coding:utf8
class Car(object):
'''
模拟汽车的简单尝试
'''
def __init__(self, make, model, year):
'''
初始化汽车的属性
:param make:
:param model:
:param year:
'''
self.make = make
self.model = model
self.year = year
self.odometer_reading = 0

def update_odomerer(self,mileage):
'''
将里程表设置为指定的值
:param mileage:
:return:
'''
self.odometer_reading = mileage

def get_descriptive_name(self):
'''
返回整洁的描述信息
:return:
'''
long_name = str(self.year) + ' ' + self.make + ' ' + self.model
return long_name.title()

def read_odometer(self):
'''
打印一条指出汽车里程的信息
:return:
'''
print 'this car has ' + str(self.odometer_reading) + ' miles on it'


class ElectricCar(Car):
'''电动车的独特之处'''

def __init__(self, a, b, c):
'''初始化父类的属性'''
super(ElectricCar, self).__init__(a, b, c)
my_tesla = ElectricCar('tesla', 'model s', 1)
print my_tesla.get_descriptive_name()
posted @ 2018-11-07 17:52  菜菜_包包  阅读(470)  评论(0编辑  收藏  举报