Static methods in Python?

后端 未结 10 917
悲&欢浪女
悲&欢浪女 2020-11-22 02:36

Is it possible to have static methods in Python which I could call without initializing a class, like:

ClassName.static_method()
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 02:55

    You don't really need to use the @staticmethod decorator. Just declaring a method (that doesn't expect the self parameter) and call it from the class. The decorator is only there in case you want to be able to call it from an instance as well (which was not what you wanted to do)

    Mostly, you just use functions though...

提交回复
热议问题