Do I need "self" and "other"?

Terry Reedy tjreedy at udel.edu
Fri Jun 27 19:08:55 EDT 2008



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"?

Yes.

A method is a function bound to a class or instance thereof.
Def statements create functions.  Parameter names are arbitrary, as long 
as they do not conflict with any global names you want to access from 
within the function.

Self (and other) are simply community conventions.  They do have they 
advantage that if they are only used as function/method parameter names, 
then they will not conflict with any module globals.

tjr




More information about the Python-list mailing list