Function Details: classmethod

Description


Transforms a method into a class method.


Extended Description


The classmethod() function is a decorator that transforms a method into a class method. Unlike a regular method, a class method receives the class as an implicit first argument, instead of an instance. This can be useful for defining alternative constructors or methods that operate on the class itself rather than instances.


Read More about classmethod from Python Documentation

Function Signature


classmethod(function: Callable) -> classmethod

Module: builtins

Parameters


function: A callable that will be transformed into a class method.


Parameter List


  • function: Callable

Return


Returns a class method for the given function.


Return Type


classmethod

Output

Explanation

This example demonstrates a common use of classmethod as an alternative constructor.