[Tutor] Methods and classes
Kent Johnson
kent37 at tds.net
Thu Sep 14 00:26:53 CEST 2006
Chris Hengge wrote:
> The deitel book has a note on page 229:
> Failure to specify an object reference (usually called self) as the
> first parameter in a method definition causes fatal logic errors when
> the method is invoked at runt-ime.
>
> Now I've got methods all over the place among several scripts that don't
> use self, and each other works fine as I'd expect.
You have to distinguish between a method (a function that is part of a
class definition) and a standalone function (not part of any class).
Python allows both. Standalone functions don't have a 'self' parameter;
class methods always do (you can give it a different name but if you
omit it you will get a runtime error when you call the method).
Kent
More information about the Tutor
mailing list