Continuing the discussion from 9.Inheritance please help, many thanks!:

Why do we need to initalize this again?

Replace this line with your code.


otherwise we don't have access to the variables through self? I agree the method is a bit tedious, the better way would be to use super() to call the parent __init__() method, but super() hasn't been covered yet


I updated the code to initialize the inherited variables. I was wondering why initialization doesn't get carried forward in inheritance.

Also, thank you for your continued help on various questions. It really helped me get through the course.


methods are function which are part of a object, you know this right?

so __init__() is also a method (a magic method to be more precise), __init__() is automatically called when you create an object instance (my_car in the exercises)

But when you inherit, __init__() of the parent class is not automatically called. We have to do this manually. super() would be the best approach:

super(ElectricCar, self).__init__(model, color, mpg)

super allows you to call parents method.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.