Extending classes __init__behavior for newbies

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Feb 13 18:01:02 EST 2011

On Mon, 14 Feb 2011 08:27:10 +1000, James Mills wrote:

> On Mon, Feb 14, 2011 at 8:21 AM, MRAB <python at mrabarnett.plus.com>
> wrote:
>> I would've done it this way:
>> class FasterShip(Ship):
>>    def __init__(self, speed=0, **kwargs):
>>        Ship.__init__(self, **kwargs)
>>        self.speed = speed
> What's the difference between calling the base class's constructor
> directly and using the super type ?

If you have *only* single inheritance, then there is no practical 
difference and no harm in using super().

If you have multiple inheritance, then you *must* use super(), otherwise 
your method will not correctly call all the superclasses that it needs to.


More information about the Python-list mailing list