静态方法@staticmethod

staticmethod 返回函数的静态方法。该方法不强制要求传递参数,名义上在类里面归类管理,但是不能使用类的变量和实例的变量是类的工具包

如下声明一个静态方法:

class Room:
t = 1
def __init__(self):
pass

@staticmethod
def body(a):
print('staticmethod %s' %a) #结果:staticmethod A

Room.body('A')
原文地址:https://www.cnblogs.com/ajaxa/p/9045962.html