PyDocs

Nav

Python Runtime Services

classmethod

builtins

decoratorDeprecated 3.11
  • @classmethod
Deprecated since 3.11, removed in 3.13. Class methods can no longer wrap other descriptors such as property().
Convert a function to be a class method.

A class method receives the class as implicit first argument,
just like an instance method receives the instance.
To declare a class method, use this idiom:

  class C:
      @classmethod
      def f(cls, arg1, arg2, argN):
          ...

It can be called either on the class (e.g. C.f()) or on an instance
(e.g. C().f()).  The instance is ignored except for its class.
If a class method is called for a derived class, the derived class
object is passed as the implied first argument.

Class methods are different than C++ or Java static methods.
If you want those, see the staticmethod builtin.
Changed in 3.9, 3.10
  • 3.9: Class methods can now wrap other descriptors such as property().
  • 3.10: Class methods now inherit the method attributes (__module__, __name__, __qualname__, __doc__ and __annotations__) and have a new __wrapped__ attribute.
0 Examples
No examples for builtins/classmethod.
See Also
No see-alsos for builtins/classmethod
0 Notes
No notes for classmethod