[Tutor] why "self" in methods?
orbitz at ezabel.com
orbitz at ezabel.com
Sun Apr 4 13:39:07 EDT 2004
Python is very explicit about many things. In C++ or Java the 'self' (called
this) is implicit, with python you explicitly give the name, as the first
parameter of your class's method, that you can access the class from. The
tutorial covers this concept. Read
http://www.python.org/doc/current/tut/node11.html
Also in the case of our fictional class Foo, something like:
bar = Foo()
bar.doIt()
Really can be interpreted as
bar = Foo()
Foo.doIt(bar)
Those two statements are synonymous, hope that helps somewhat.
On Sat, 03 Apr 2004 17:52:27 -0900
Chris Lott <chris at chrislott.org> wrote:
> Why do object methods need the (self) parameter rather than just
> accepting () as a function can? I mean, given:
>
> class Foo:
> def doIt(self):
> print "did it"
>
> why couldn't it be:
> def doIt():
>
> c
> --
> Chris Lott
> http://www.chrislott.org/
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list