属性方法:通过@property把一个方法变成一个静态属性
实例:
调用航班的状态
# 查看航班状态 import random class CheckState(object): def __init__(self,name): self.name=name def checkState(self): print('正在检查%s航班的状态...'%self.name) state = random.randrange(0,3) return state @property def flightStatu(self): state = self.checkState() if state == 0: print('%s航班正常。'%self.name) elif state == 1: print('%s航班延误。'%self.name) else: print('%s航班一起飞。'%self.name) c = CheckState('F001') c.flightStatu
运行结果: