methods and class methods

Daniel Fetchinson fetchinson at googlemail.com
Tue Mar 31 11:30:26 EDT 2009


> I just learned python programming and is wondering how to change a method to
> a class method.

class x( object ):
    @classmethod
    i_will_be_a_class_method( cls ): pass

> Also what are the differences between a method and class method.

A class method receives the class as its first argument while an
ordinary method receives the instance as its first argument. This fact
is reflected in the convention that for class methods the first
argument typically is called cls while for ordinary methods it's
called self.

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown



More information about the Python-list mailing list