[newbie] - what is self variable?

Pete Shinners shredwheat at mediaone.net
Wed May 30 11:36:30 EDT 2001


"Cervantes" <CervantesVive at hotmail.com> wrote
> i've already written a few python scripts but am just learning
> oop. i notice many examples make use of a 'self' variable
> under __init__ , what does this referr to?
>
> is it like a this pointer?

it is very much like the C "this" pointer. actually, the
name isn't special in anyway, you could use "this" if you
wanted, but i've yet to see any code that uses something
besides "self".

unlike C, you _must_ use this self variable when referencing
members and methods for the class.

this "self" is always the first argument passed to any
method functions of a class. when you "forget" to include
it in the method argument list, you'll quickly get
"wrong number of argument" errors when you try to call
the method.








More information about the Python-list mailing list