[Tutor] Method question?
W W
srilyk at gmail.com
Fri May 2 20:57:15 CEST 2008
I think I'm beginning to understand how classes/methods work now, I'm
sure further understanding will come with practice.
Thanks for the help and suggestions!
-Wayne
On Fri, May 2, 2008 at 1:42 PM, Kent Johnson <kent37 at tds.net> wrote:
> On Fri, May 2, 2008 at 2:20 PM, W W <srilyk at gmail.com> wrote:
>
> > 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.
>
> 'self' is roughly like 'this' in C++. Unlike C++, self must be
> explicit - it is listed as a method parameter and it must be used for
> attribute access.
>
>
> > Let me see if I
> > understand correctly:
> >
> > class myClass():
>
> or, more idiomatic (class names start with upper case letters) and
> modern (inherit from object to create a new-style class):
> class MyClass(object):
>
> >
> > 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?
>
> Yes.
>
> Kent
>
--
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