[Tutor] Method question?

Kent Johnson kent37 at tds.net
Fri May 2 19:17:48 CEST 2008


On Fri, May 2, 2008 at 12:55 PM, W W <srilyk at gmail.com> wrote:
> I'm playing around with pyGTK, and I have a question to see if I'm
>  understanding things correctly.
>
>  Is a method just a function inside a class?

Pretty much. It also has a required 'self' parameter which gets the
value of the object on which the method is called.
>
>  i.e.
>
>  def myFunction():
>     print "This is a function"
>
>  class myClass:
>     def myMethod():

should be
  def myMethod(self):
>         print "This is a method"
>
>  and to call:
>
>  myFunction()
>
>  I tried to call the method via. myClass.myMethod() and
>  x = myClass

This just makes x an alias for the class object. Should be
  x = myClass()

>  x.myMethod()

then this will work.

Kent


More information about the Tutor mailing list