Method is just a function object created by def statement.
class method
If we need to use class attributes
static method
We do not have any info about the class
Instance method
Instance method but inner working of instance method is the same as the class method. Actually, Python automatically maps an instance method call to a class method.
Class Method and Instance Method
The method foo() is designed to process instances, we normally call the method through instance:
Note: that we pass the instance a as an argument of the foo() method.
1:Bound method (instance call):
To call the method we must provide an instance object explicitly as the first argument. In other words, a bound method object is a kind of object that remembers the self instance and the referenced function.
Python automatically packages the instance with the function in the bound method object, so we don't need to pass an instance to cal the method.
2:Unbound method (class call):
Accessing a function attribute of a class by qualifying the class returns an unbound method object:
Note: In Puython 3.0, the notion of unbound method has been dropped, and what we describe as an unbound method here is treated as a simple function in 3.0.
Static Method
Static methods are used when we need to process data associated with classes instead of instances. A static method has no self argument and it is nested in a class and is designed to work on class attributes instead of instance attributes.
I'll use function decorator(@) for static method, and the syntax looks like this:
Internally, the definition has the same effect as the name rebinding:
Suppose we have a typical instance counting code like this:
Then, we make three instances:
Now that we have static method, we can call it in two ways:
call from class
call from instances
Instance, static, and class methods
Here is a simple code that has all types of methods:
Related Searches to Python - class method vs static method
python class method vs instance methodpython call static method within class'staticmethod' object is not callablepython static method privatepython static memberinstance method vs static method in pythonpython classmethod initpython 3.5 static methodpython class method vs static methodpython call static method within classinstance method vs class method javapython call class method from instanceinstance method vs static method in pythonpython static memberstatic method and instance method in pythonunbound method python