@classmethod和@staticmethod对初学者的意义? [重复]

牧云@^-^@ 提交于 2020-08-16 19:23:41

问题:

This question already has an answer here: 这个问题在这里已有答案:

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!