屬性方法:經過@property把一個方法變成一個靜態屬性dom
實例:spa
調用航班的狀態code
# 查看航班狀態 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
運行結果:blog