It is a built-in function decorator that's evaluate the function. The result of that evaluation shadows decide our function definition. A class method receives the
class as most first argument like as an instance method for receiving the instance.
Syntax:
class C(object):
@classmethod
def fun(cls, arg1, arg2, ...):
fun: function which is needs to be converted into a class method
returns: a class method for define function.
A class method is a method which is bound to the class but not for the object of the class.
Static Method : It's does not receive an most first argument.
Syntax:
class C(object): @staticmethod
def fun(arg1, arg2, ...):
returns: a static method for function fun.
static method is like a method which is bound to a class but its not a object of the class.
Difference between Class and Method :
- A class method takes cls as first parameter but a static method needs not a any parameters.
- A class method can access or modify class state while a static method can’t access or modify it.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Class Methods:
It is a built-in function decorator that's evaluate the function. The result of that evaluation shadows decide our function definition. A class method receives the class as most first argument like as an instance method for receiving the instance.
Syntax:
fun: function which is needs to be converted into a class method
returns: a class method for define function. A class method is a method which is bound to the class but not for the object of the class.
Static Method : It's does not receive an most first argument.
Syntax:
returns: a static method for function fun. static method is like a method which is bound to a class but its not a object of the class.
Difference between Class and Method :
- A class method takes cls as first parameter but a static method needs not a any parameters.
- A class method can access or modify class state while a static method can’t access or modify it.