Why do class methods always need 'self' as the first parameter?
ericsnowcurrently at gmail.com
Thu Sep 1 04:07:42 CEST 2011
On Wed, Aug 31, 2011 at 7:47 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Thu, Sep 1, 2011 at 10:48 AM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> Python classes have a lot of dynamism made possible by the fact that methods
>> are just wrappers around functions with an explicitly declared "self". That
>> dynamism is rarely used, but not *that* rarely, and is very useful when
>> used. Implicit self would likely negate all that.
> Hmm. Got any examples sitting around? I'm curious as to what you can
> do with this. I'm like a kid with a new chemistry set - "what happens
> if I mix a little of everything together?"...
First thing that comes to mind is calling a base class's
implementation of a method:
def __init__(self, value):
self.value = value
More information about the Python-list