What is the "self" name always referring to...?

Fredrik Lundh fredrik at pythonware.com
Wed Dec 10 01:57:43 EST 2003


Todd Gardner wrote:

> Pardon my extremely ignorant newbie questions.
>
> Where can I go to find more information about the "self" argument?
>
> Is there something special about the word "self" or did Mr. Guido van
> Rossum just decide to us the word arbitrarily?
>
> More precisely it seems that most all classes have "self" as the first
> parameter.  This may be directly obvious but is the word "self" always
> referring to the class or the function it is used in?

self is used in *methods* (which are functions associated with
classes), and is used to refer to the current instance of the class
that method belongs to.

for more on classes, see the tutorial:

    http://www.python.org/doc/current/tut/node11.html

the FAQ also contains some helpful entries:

http://www.python.org/doc/faq/programming.html#what-is-self
http://www.python.org/doc/faq/general.html#why-must-self-be-used-explicitly-in-method-definitions-and-calls

> Is it a reserved word?

nope, but it's usually a good idea to treat it as if it were.

</F>








More information about the Python-list mailing list