Simple questions about classes

sismex01 at hebmex.com sismex01 at hebmex.com
Tue Feb 11 14:51:28 EST 2003


> From: nvivo at terra.com.br [mailto:nvivo at terra.com.br]
> Sent: Tuesday, February 11, 2003 1:48 PM
> 
> Hi, i`m a newbie in python, and i was reading the tutorial (and some
> source codes), then i noticed that every function inside a class
> receives the 'self' parameter.
> 
> Like this exemple in python tutorial:
> 
> ---
> class MyClass:
>     "A simple example class"
>     i = 12345
>     def f(self):
>         return 'hello world'
> ---
> 
> I think self points to the class, but why do we need to pass this
> parameter to every function?
>

"self" is the current instance, and as to why make it
explicit instead of implicit (like C++), that decision
was made by Guido van Rossum a long time ago.

-gustavo





More information about the Python-list mailing list