标签:col nbsp 提升 obj class div instance __init__ tran
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)
标签:col nbsp 提升 obj class div instance __init__ tran
原文地址:https://www.cnblogs.com/Attacking-vincent/p/12974963.html