How super() works with __init__() method in multiple inheritance?
super support cooperative multiple inheritance in a dynamic execution environment. This use case is unique to Python and is not found in statically compiled languages or languages that only support single inheritance.
class F: def __init__(self): print('F%s' % super().__init__) super().__init__() class G: def __init__(self): print('G%s' % super().__init__) super().__init__() class H: def __init__(self): print('H%s' % super().__init__) super().__init__() class E(G, H): def __init__(self): print('E%s' % super().__init__) super().__init__() class D(E, F): def __init__(self): print('D%s' % super().__init__) super().__init__() class C(E, G): def __init__(self): print('C%s' % super().__init__) super().__init__() class B(C, H): def __init__(self): print('B%s' % super().__init__) super().__init__() class A(D, B, E): def __init__(self): print('A%s' % super().__init__) super().__init__() a = A() print(a)
Sample output of above program.
A bound method D.__init__ of __main__.A object at 0x000000000369CFD0 D bound method B.__init__ of __main__.A object at 0x000000000369CFD0 B bound method C.__init__ of __main__.A object at 0x000000000369CFD0 C bound method E.__init__ of __main__.A object at 0x000000000369CFD0 E bound method G.__init__ of __main__.A object at 0x000000000369CFD0 G bound method H.__init__ of __main__.A object at 0x000000000369CFD0 H bound method F.__init__ of __main__.A object at 0x000000000369CFD0 F method-wrapper '__init__' of A object at 0x000000000369CFD0 __main__.A object at 0x000000000369CFD0
2019-07-08T07:36:55+05:30
2019-07-08T07:36:55+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution