名称 | 语法 | 作用 | 示例 |
类方法 | @classmethod | 使方法只能访问类变量 不能访问实例变量 |
@classmethod def run(cls): print(cls) |
静态方法 | @staticmethod | 使方法不能访问实例变量和类变量 |
@staticmethod def show(): print('我是静态方法') |
属性方法 | @property | 使方法变成一个属性 |
@property def flight_status(self): status = self.checking_status() if status == 0 : print("flight got canceled...") elif status == 1 : print("flight is arrived...") elif status == 2: print("flight has departured...") else: print("cannot confirm ...") |
【python之路】【之前没搞明白的】7面向对象(类方法、静态方法、属性方法)
猜你喜欢
转载自www.cnblogs.com/watalo/p/12330354.html
今日推荐
周排行