Classmethod() Function In Python

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:

class TV:

    def showProgram():

        print("TV Program in progress")

    classmethod(showProgram)       

 

TV.showProgram()

 

Output:

TV Program in progress


Copyright 2023 © pythontic.com