Built-in Functions and Types
classmethod()
Wrap a function in a descriptor that binds the class as its first argument. Access through a subclass supplies that subclass, making class methods useful for alternative constructors that preserve subclass behavior. Both class and instance access bind the class, not the instance. In Python 3.13 classmethod no longer supports wrapping other descriptors such as property; use an ordinary function.
Formal Syntax & Structure
python syntaxpython
classmethod(function, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| function | function | Method whose first argument receives the class. |
Return Value
classmethod
Descriptor producing a class-bound method on lookup.
Working Example
Example Snippetpython
class Report: @classmethod def create(cls): return cls()
class Summary(Report): pass
print(type(Report.create()).__name__)print(type(Summary.create()).__name__)