class Car(): # Parent Class 1
def __init__(self, brand, model, year):
self.brand = brand
self.model = model
self.year = year
def get_info(self):
return "Car: " + self.model + "\nBrand: " + self.brand + "\nYear: " + self.year
def get_fuel_info(self):
return 'Class Car'
class Fuel_type(): # Parent Class 2
def __init__(self, fuel):
self.fuel = fuel
def t(self):
return "Class Fuel_Type"
class MyCar(Car, Fuel_type): # Child Class derived from Car() & Fuel_type()
def __init__(self, brand, model, year, fuel):
super().__init__(brand, model, year)
super().__init__(fuel)
car0 = MyCar('Tesla', 'Model S', '2016', 'Electric')
error:
Traceback (most recent call last):
File "learning.py", line 23, in <module>
car0 = MyCar('Tesla', 'Model S', '2016', 'Electric')
File "learning.py", line 20, in __init__
super().__init__(fuel)
TypeError: __init__() missing 2 required positional arguments: 'model' and 'year'
I don't know how to use the constructors of both the parent classes since how I am trying is giving me an error. Is there a way to get it right?
Although, if I comment out
the line
super().__init__(brand, model, year)
super().__init__(fuel)
I can use all the functions of both the parent classes.