What is "self"?

marduk usernet at marduk.letterboxes.org
Thu Sep 22 22:16:49 EDT 2005


On Thu, 2005-09-22 at 21:36 -0400, Wayne Sutton wrote:
> OK, I'm a newbie...
> I'm trying to learn Python & have had fun with it so far.  But I'm having 
> trouble following the many code examples with the object "self."  Can 
> someone explain this usage in plain english?

"self" references the object itself.  It's usually also called "this" on
other languages (C++ & Java I believe).  In Python, when you define a
class method, the reference to the object is passed explicitly rather
than implicitly.

Also, the name "self" is used by convention.  You could use any name if
you wanted, but if you want other people to understand your code then
use "self".

Is that plain English enough?  




More information about the Python-list mailing list