classmethod() function in Python

The classmethod() built-in function is used to make a method declared inside a class as a static method

Built-in Functions Updated 3 Mar 2017 1 min read

Function Name

classmethod

Function Signature

classmethod(function)

Function Overview

  • The function classmethod() in Python transforms a function declaration into a static function.

  • The function should be called at the same indent as the method's def statement.

  • The same behavior is achieved by using the function decorator @staticmethod.

Example

python
class TV:

    def showProgram():

        print("TV Program in progress")

    classmethod(showProgram)

TV.showProgram()

Output

Output
TV Program in progress