[Tutor] Method question?
Kent Johnson
kent37 at tds.net
Fri May 2 20:42:24 CEST 2008
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
More information about the Tutor
mailing list