Python classmethod 修饰符简单使用

Python classmethod 修饰符简单使用

class A(object):
value = 1
def func1(self):
print('func1')

@classmethod
def func2(cls):
print('func2')
print(cls.value)
cls().func1() # 调用 func1方法


if __name__=="__main__":
A.func2() # 不需要实例化
输出结果:

func2
1
func1

原文地址:https://www.cnblogs.com/xiaohai123/p/13586380.html