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

如下声明一个静态方法:

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

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

Room.body('A')
posted on 2018-05-16 14:45  Python哥  阅读(275)  评论(0编辑  收藏  举报