Class Method vs Static Method

The basic difference between the class method vs Static method in Python and when to use the class method and static method in Python.

  • A class method takes cls as the first parameter while a static method needs no specific parameters.
  • A class method can access or modify the class state while a static method can’t access or modify it.
  • In general, static methods know nothing about the class state. They are utility-type methods that take some parameters and work upon those parameters. On the other hand class methods must have class as a parameter.
  • We use @classmethod decorator in Python to create a class method and we use @staticmethod decorator to create a static method in Python.

classmethod() in Python

The classmethod() is an inbuilt function in Python, which returns a class method for a given function.

Similar Reads

classmethod() in Python Syntax

Syntax: classmethod(function) Parameter :This function accepts the function name as a parameter. Return Type:This function returns the converted class method....

Python classmethod() Function

The classmethod() methods are bound to a class rather than an object. Class methods can be called by both class and object. These methods can be called with a class or with an object....

Class Method vs Static Method

The basic difference between the class method vs Static method in Python and when to use the class method and static method in Python....

Example of classmethod in Python

Create a simple classmethod...

Python @classmethod Decorator

...