I have two base classes A
and B
each of them have a method myfunc
, which prints out a different character.
class A:
def myfunc(self):
print('A')
class B:
def myfunc(self):
print('B')
I have one more class C
which is inheriting from A
and B
both. In class C
I have overridden myfunc
and called super
over it.
class C(B, A):
def myfunc(self):
super().myfunc()
Now if I execute following code, it prints only one character
x = C()
x.myfunc()
Output:
B
I tried print(C.__mro__)
which gives me (<class '__main__.C'>, <class '__main__.B'>, <class '__main__.A'>, <class 'object'>)
So it should go to class A
and print character A
also. right?
Also if I switch the order of inheritance like C(A,B)
it and use the same code , it is skipping class B
.
My questions:
- Why it's skipping
class A
? - How to execute
myfunc
method in both classesA
andB
I looked up similar discussion but found it confusing.