Do I need "self" and "other"?

Luis Zarrabeitia kyrie at uh.cu
Fri Jun 27 20:15:51 EDT 2008


On Friday 27 June 2008 06:41:22 pm Kurda Yon wrote:
> OK, I see. In the given example "self" is just a name which can be
> replace by whichever (valid) name. Is that always like that? I mean,
> does "slef" have a special meaning in some cases or it is always "just
> a name like any other"? I am asking that because "self" is highlighted
> in my text editor, so I assume that it can have a special meaning. I
> also heard that "self" refers to a object and I am not sure what that
> "refers" means.

It's a name, like any other.
It only has special meaning on the minds of most python programmers. That name 
is used, by convention (and only because of convention) to refer the the ... 
erm... 'self' object.

That said, of all python conventions, it is perhaps the one most zealously 
followed. That's why your editor highlights it.

So, code will not break if you use any other valid name instead of self. But 
you shouldn't. Everything will work perfectly - except the readability.

Cheers,

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie



More information about the Python-list mailing list