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

@classmethod

I don't fully understand how @classmethod work in python and the use of it. I understand the oop concepts in c++ but this is weird. It's something like constructor in c++?

2nd Oct 2020, 8:32 PM
tibi
tibi - avatar
9 Answers
+ 3
Abhay i think the author ask about analog @classmethod in c++. I can't answer, because in c++ it is an other rule for classes
2nd Oct 2020, 9:31 PM
Petr
+ 3
I am asking if @classmethod works like constructor overloading in c++.
2nd Oct 2020, 9:45 PM
tibi
tibi - avatar
+ 3
Abhay Yes, they are
3rd Oct 2020, 7:12 AM
Kevin ★
+ 2
Petr I don't know about anything like class method in c++ yet , and I think the person is asking if classmethod in python is similar to constructor in c++, but I maybe wrong !!
2nd Oct 2020, 9:40 PM
Abhay
Abhay - avatar
+ 2
Kevin ★ aren't static methods in python similar like static methods in c++?
3rd Oct 2020, 7:08 AM
Abhay
Abhay - avatar
+ 1
__init__ is a constructor like constructor in c++ , Here is a good discussion about class method and static method https://stackoverflow.com/questions/136097/difference-between-staticmethod-and-classmethod
2nd Oct 2020, 9:27 PM
Abhay
Abhay - avatar
+ 1
tibi @classmethod is pretty much the same as static methods in c++ Abhay got it right in his first answer: __init__ == constructor
3rd Oct 2020, 12:44 AM
Kevin ★