>> self is a special varianble
> "special variable" could be confusing. Python has no "special 
> variables". "self" is used by convention.

Good point. The name self is not special it is its role that is 
special.

thus

class C:
    def m(s,p):
        print p

c = C()
c.m(42)

Thus we define method m to have two parameters s and p
but when we call m we only pass in one argument. Python
then takes this and turns it into

C.m(c,42)

The specialness of 'self' is that although we specify it, and can 
access it,
in the method definition we do not specify it in the message to the 
class
that invokes the method.

Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to