Python静态类方法(转载)
1. 静态类方法@staticmethod和@classmethod的关系 1.1. 基础介绍
1 2 3 4 5 6 7 8 9 10 11 |
class MyClass: def method(self): return 'instance method called', self @classmethod def classmethod(cls): return 'class method called', cls @staticmethod def staticmethod(): return 'static method called' |
实例方法 MyClass调用的第一个方法method是常规实例方法。这是您大多数时候会使用的基本,简洁的方法类型。您可以看到该方法采用一个参数,self该参数指向MyC… 阅读更多 »Python静态类方法(转载)