Classes: The Car exercise the Super syntax


#1

Hi Codecademy,

I have a question related to the child class, the inheritence, and the super syntax:

If we import all of the parent’s arguments here in line 16:

 def __init__(self, model, color, mpg, battery_type):

Why do we need to import them again here in line 18:

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

isnt that repetitive?

Would amending line 18 to this work:

super().__init__(model, color, mpg)'''

And why? What does the code inside the super() parentheses do?

Thanks for all of your help so far.

Here is the link:


#2

because the child init method (of ElectricCar) overwrites the parent init method, so super() is actually preventing you from writing repetitive code.

super() is a built-in function, so the arguments for super() indicate the class of which the parent method should be called and on which instance. In python3, if super() is used in a method, you can leave these arguments out, python will figure it out