python 静态方法和类方法

      python 静态方法和类方法已关闭评论

class TestClassMethod(object):

METHOD = ‘method hoho’

def __init__(self):
self.name = ‘leon’

def test1(self):
print ‘test1’
print self

@classmethod
def test2(cls):
print cls
print ‘test2’
print TestClassMethod.METHOD
print ‘—————-‘

@staticmethod
def test3():
print TestClassMethod.METHOD
print ‘test3’

if __name__ == ‘__main__’:
a = TestClassMethod()
a.test1()
a.test2()
a.test3()
TestClassMethod.test3()