Why do we use "@classmethod"? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why do we use "@classmethod"?

I get the same results when I define a class method in the following two ways. 1-) Using @classmethod @classmethod def somemethod(cls) Some Codes 2-) Normally def somemethod() Some Codes In both ways I can reach the method using name of the class and I can do same operations using the method. The only difference is that I can call the method via object names when I declare the method in the first way. I think there should be some significant differences between these two methods. Is it?

26th Nov 2017, 11:26 AM
Adem şahin
Adem şahin - avatar
1 Answer
0
Yes ,there are difference between the first way ,he does a reference to class ,in first way the class can be taken in consideration to instantiate the object and second way no.
17th Feb 2018, 1:59 AM
J G
J G - avatar