[Tutor] Method question?
W W
srilyk at gmail.com
Fri May 2 20:20:55 CEST 2008
On Fri, May 2, 2008 at 12:17 PM, Kent Johnson <kent37 at tds.net> wrote:
<snip>
> This just makes x an alias for the class object. Should be
> x = myClass()
>
> > x.myMethod()
>
> then this will work.
Ah! Thank you!
I knew/guessed the alias bit from my experience with C++, but I
couldn't figure out exactly what I needed. I've seen the "self"
reference before, but I never really understood it. Let me see if I
understand correctly:
class myClass():
creates a new "data type"(?), called myClass, and
x = myClass()
creates a variable with the type of "myClass", similar to foo = dict()
and the method inside myClass defined as myMethod(self), can be called
on the data type "myClass" like this:
x.myMethod()
is that fairly accurate?
--
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn't. - Primo Levi
More information about the Tutor
mailing list