Python classmethod() Method

The classmethod() method transform a method into a class method.

It is recommended to use @classmethod decorator instead of the classmethod()

Syntax:

classmethod(function)

Parameters:

function: The function to be converted to the class method.

Return Value:

Returns the class method.

The following example shows the working of classmethod() method.

Example: classmethod()
class student:
    name = 'John'
    
     def show_name(self):
        print("The student's name is ",self.name)

student.show_name = classmethod(student.show_name)
student.show_name()
Output
The student's name is  John