静态方法使用 @staticmethod 修饰

类成员方法使用 @classmethod 修饰
 
class MyClass(object):
    @staticmethod
    def test1():
        print("static test1")
 
    @classmethod
    def test2(cls):
        print("class method ", cls)
 
if __name__ = '__main__'
    MyClass.test1()
    MyClass.test2()

相关文章:

  • 2022-01-27
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-01-26
  • 2022-12-23
猜你喜欢
  • 2021-09-28
  • 2022-01-22
  • 2021-10-04
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案