Simple questions about classes

Grant Edwards grante at
Tue Feb 11 21:23:09 CET 2003

In article <bbb4a9e1.0302111148.48dc074b at>, Natan wrote:

> I think self points to the class,

No, self points to an instance of the class.

> but why do we need to pass this parameter to every function?

While you have to declare it, you don't have to pass it when
you're calling a bound method. You only have to pass it when
calling an unbound method:

class A:
    def foo(self,arg):
        print "foo:",`self`,arg
    def bar(self,arg):
        print "bar:",`self`,arg
a1 = A()
a2 = A()"asdf"),"asdf")"qwer"),"qwer"),42)

Grant Edwards                   grante             Yow!  .. Do you like
                                  at               "TENDER VITTLES?"?

More information about the Python-list mailing list