We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

classmethod

classmethod(function)

Returns a class method for function.

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, ...): ...

The @classmethod form is a function decorator — see def for details.

It can be called either on the class (such as C.f()) or on an instance (such as 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 staticmethod.

For more information on class methods, consult the documentation on the standard type hierarchy in chapter 3 of the [Python Reference Manual][17] (at the bottom). (New in version 2.2.) (Changed in version 2.4: Function decorator syntax added.)