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

Chris Rebert clp2 at rebertia.com
Wed Aug 31 14:31:21 EDT 2011

On Wed, Aug 31, 2011 at 10:12 AM, Prasad, Ramit
<ramit.prasad at jpmorgan.com> wrote:
>>def double(obj): return 2*obj.value
>>class C:
>>     def __init__(self, val):
>>         self.value = val
>>c = C(3)
>>C.double = double
>>c.doub = double
>># not c.double as that would mask access to C.double in c.double() below
>>print(double(c), C.double(c), c.double(), c.doub(c))
> Sorry if I get some of the following terminology wrong, I get a bit confused on Python terms. I hope the following is still coherent. (Is there a dictionary of Python terminology?)

The documentation has a glossary:
It's not entirely comprehensive though.


More information about the Python-list mailing list