What is a class method?

Terry Reedy tjreedy at udel.edu
Mon Aug 23 01:26:07 EDT 2010


On 8/22/2010 11:53 PM, Paulo da Silva wrote:

>> Please read this first:
>> http://docs.python.org/library/functions.html#classmethod
>>
>> Then ask us questions :)
>
> I did it before posting ...

When you ask a question, it help people answer if they know what you 
have already tried and failed with ;-)

> The "explanation" is not very clear. It is more like "how to use it".

A function accessed as a class attribute is normal treated as an 
instance function/method -- with an instance of the class as the first 
argument. A class method takes the class as the first argument. A 
'staticmethod' is a function that takes neither as the first argument 
and, with one esoteric exception, does not need to be a class attribute 
but is for convenience.

-- 
Terry Jan Reedy




More information about the Python-list mailing list