What is class method?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Tue Aug 26 16:15:26 EDT 2008


Hussein B a écrit :
> Hi,
> I'm familiar with static method concept,

Which is more often than not useless in Python - we have true functions 
and modules.

> but what is the class method?

Short answer : It's a method that can be looked up upon both the class 
or an instance of it, and takes the class itself (instead of the 
instance) as first parameter.

> how it does differ from static method?

static methods don't receive the class object as first param.

> when to use it?

When you need to access the class (using polymorphic dispatch), don't 
care about the instance itself, and want to be able to call the method 
on both the class or an instance.




More information about the Python-list mailing list