Why do class methods always need 'self' as the first parameter?

Eric Snow 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:

class X(Y):
    def __init__(self, value):
        Y.__init__(self)
        self.value = value

-eric

>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list