静态方法和类成员方法
静态方法和类成员方法分别在创建时分别被装入Staticmethod类型和Classmethod类型
的对象中。
静态方法的定义没有self参数,且能够被类本身直接调用。
类方法的定义时需要名为cls的类似于self的参数,类成员方法可以直接用类的具体对象
调用。但cls参数是自动被绑定到类的。
__metaclass__ = typeclass MyClass: def smeth(): print 'This is a static method' smeth = staticmethod(smeth) def cmeth(cls): print 'This is a class method of', cls cmeth = classmethod(cmeth)
__metaclass__ = typeclass MyClass: @staticmethod def smeth(): print 'This is a static method' @classmethod def cmeth(cls): print 'This is a class method of', cls