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

如下声明一个静态方法:

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

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

Room.body('A')

相关文章:

  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-06-22
  • 2021-09-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2019-11-16
  • 2019-06-03
  • 2018-06-30
相关资源
相似解决方案