Skip to main content

classmethod() in Python

In Python, classmethod() is an built-in function. The classmethod() method returns a class method for the given function.

A class method is a method that is bound to a class rather than its object. It doesn't require creation of a class instance. 

It can be called as a both class or object.

Syntax:

classmethod(function)

Parameter:

This function accepts the function name as a parameter that needs to be converted into a class method.

Return Values:

This function returns the converted class method.

Example:

class abc():
    place = "xyz"
    
    def place_1(obj):
        print("The place is:",obj.place)
        
abc.place_1 = classmethod(abc.place_1)
abc.place_1()

Output: The place is: xyz

Tags
Submitted by devanshi.srivastava on July 8, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.