【python----发轫之始】【实例化车类型】
class Vehicle(object): trans_type = ‘SUV‘ def __init__(self, size, speed): self.size = size self.__speed = speed def show_info(self): print("我所属的类型为:{0},速度为:{1}km/h,体积为:{2}".format(self.trans_type, self.__speed, self.size)) def move(self): print("我已向前移动了50米!") def set_speed(self, new_speed): self.__speed = new_speed def get_speed(self): print("我的时速为:{0}".format(self.__speed)) def speed_up(self): self.__speed += 10 print("我的速度由{0}km/h提升到了{1}km/h".format(self.__speed - 10, self.__speed)) def speed_down(self): self.__speed -= 15 print("我的速度由{0}km/h下降到了{1}km/h".format(self.__speed + 15, self.__speed)) def transport_identify(name): if isinstance(name, Vehicle): print("类型匹配!") else: print("类型不匹配!") if __name__ == ‘__main__‘: v = (3.6, 1.9, 1.75) car = Vehicle(v, 20) car.show_info() car.set_speed(40) car.get_speed() car.speed_up() car.speed_down() transport_identify(car)
相关推荐
heyboz 2020-10-21
lukezhong 2020-10-14
tangxiong0 2020-09-03
zhaowj00 2020-07-05
寻常白昼 2020-06-14
luvhl 2020-06-08
oXiaoChong 2020-06-03
chenlxhf 2020-05-06
是一道经常出现在前端面试时的问题。如果只是简单的了解new关键字是实例化构造函数获取对象,是万万不能够的。更深入的层级发生了什么呢?同时面试官想从这道题里面考察什么呢?下面胡哥为各位小伙伴一一来解密。
haohong 2020-04-08
JF0 2020-03-20
fanhuasijin 2020-03-01
横云断岭 2020-02-20
zhouyuqi 2020-01-20
kong000dao0 2020-01-11
年轻就要对味 2014-07-11
发条戏子 2019-12-27
王志龙 2019-12-26
duanlove技术路途 2019-12-20