问题:
This question already has an answer here: 这个问题在这里已有答案:
- What is the difference between @staticmethod and @classmethod? @staticmethod和@classmethod有什么区别? 23 answers 23个答案
Could someone explain to me the meaning of @classmethod
and @staticmethod
in python? 有人可以向我解释@classmethod
和@staticmethod
在python中的含义吗? I need to know the difference and the meaning. 我需要知道差异和意义。
As far as I understand, @classmethod
tells a class that it's a method which should be inherited into subclasses, or... something. 据我所知, @classmethod
告诉一个类,它是一个应该继承到子类的方法,或者......某种东西。 However, what's the point of that? 但是,重点是什么? Why not just define the class method without adding @classmethod
or @staticmethod
or any @
definitions? 为什么不在不添加@classmethod
或@staticmethod
或任何@
definitions的情况下定义类方法?
tl;dr: when should I use them, why should I use them, and how should I use them? tl; dr:我应该何时使用它们, 为什么要使用它们,我应该如何使用它们?
I'm pretty advanced with C++, so using more advanced programming concepts shouldn't be a problem. 我在C ++方面非常先进,所以使用更高级的编程概念应该不是问题。 Feel free giving me a corresponding C++ example if possible. 如果可能的话,请随意给我一个相应的C ++示例。
解决方案:
参考一: https://stackoom.com/question/p6Nr/classmethod和-staticmethod对初学者的意义-重复参考二: https://oldbug.net/q/p6Nr/Meaning-of-classmethod-and-staticmethod-for-beginner-duplicate
来源:oschina
链接:https://my.oschina.net/u/4438370/blog/4303334