This question already has an answer here: 這個問題在這裏已有答案: python
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的狀況下定義類方法? spa
tl;dr: when should I use them, why should I use them, and how should I use them? tl; dr:我應該什麼時候使用它們, 爲何要使用它們,我應該如何使用它們? .net
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 ++示例。 code