class Parent:
def __init__(self, a):
self.a = a
class Child1(Parent):
def __init__(self, a, b):
super().__init__(a)
self.b = b
class Child2(Parent):
def __init__(self, a, c):
super().__init__(a)
self.c = c
class GrandChild(Child1, Child2):
def __init__(self, a, b, c):
Child1.__init__(self, a, b)
Child2.__init__(self, a, c)
def addition(self):
return self.a + self.b + self.c
res = GrandChild(1, 2, 3)
res.addition()
I am trying to add 3 number using hybrid inheritance and complier showing
TypeError:Child2.init() missing 1 required positional argument: 'c'
Any help would be appreciable
The correct way to use
superwith__init__is to__init__with only those parameters you need to use directly, and to accept arbitrary keyword arguments.super().__init__once, passing any keyword arguments you don't know what to do with.See https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ for an explanation of the 3 rules listed above.