Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python – Find Class Method for Given Function – classmethod() with Examples

classmethod() function is used to transform a function into a class method in Python. classmethod() did not require the creation of object of a class. It deals with the class itself. That’s why first argument is always the name of class itself.
classmethod() function is a part of Python Built-in Functions.


Syntax of classmethod() Function

The syntax of classmethod() function in Python is:

In Python latest version we use @classmethod decorator for classmethod definition.


Parameters of classmethod() Function in Python

function – Where function is a method/function that needs to converted into a classmethod.



classmethod() function is available and compatible with both Python 2.x and 3.x.


Return Value of classmethod() Function in Python

classmethod() function returns a class method for the given input (function – parameter).


Python classmethod() Function Example 1

The ID is: 1833355


Python classmethod() Function Example 2

Jackie's ID is: 18365489
Angela's ID is: 145328

LearnAndLearn.com © 2018 - All rights reserved