[Tutor] Methods and classes

Luke Paireepinart rabidpoobear at gmail.com
Thu Sep 14 07:58:30 CEST 2006


[snip some]
>> So just make sure I always declare self for methods (functions in
>> classes)? Is this unique to python? or do some other languages already
>> include self, and just hide it from the programmer? 
>>     
>
> All the OO languages I know have a similar concept. Python is more 
> explicit than most. Java has a 'this' variable that is magically defined 
> in the scope of any method. For most accesses to member variables and 
> methods you don't even have to specify 'this' - the language figures it 
> out for you. Ruby uses a naming convention to refer to attributes inside 
> a method (attribute names start with @)
[snip some more]

Note that you can call the class instance that's passed around to the 
functions whatever you want.

'self','fish', 'banana', 'octopus', 's'.
However, if you attempt to name it something other than 'self', or occasionally 's',
other programmers might get scared.  Especially if you name it 'int' or something :)

HTH,
-Luke
> Kent
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   



More information about the Tutor mailing list