+ 2

What are class and static methods in python?

Can someone explain me what they are and what they do in python and perhaps show me some examples? i dont understand them quite well 😅

19th Dec 2021, 3:54 AM
enzore
enzore - avatar
1 Antwort
+ 3
CLASS METHOD= A class method is a method that is bound to the class and not the object of the class. They have the access to the state of the class as it takes a class parameter that points to the class and not the object instance. It can modify a class state that would apply across all the instances of the class. For example, it can modify a class variable that will be applicable to all the instances. STATIC METHOD= A static method is also a method that is bound to the class and not the object of the class. A static method can’t access or modify the class state. It is present in a class because it makes sense for the method to be present in class.
19th Dec 2021, 4:04 AM
Neil Young