I am new to multiple and multilevel inheritance. I was trying to execute an example:
class First(object):
def __init__(self):
super().__init__()
print("first")
class Second(object):
def __init__(self):
super().__init__()
print("second")
class Third(First, Second):
def __init__(self):
super().__init__()
print("third")
Third()
The output I got is:
second
first
third
<__main__.Third at 0x21bbaf2fc88>
Could anyone please explain me the reason for this output? I was expecting the output to be:
first
second
third
As __init__() of third would call __init__() of First class (because it is first in the parent list) which would print first then second class's __init__() and then finally __init__() of third class.
MRO prints what I expected.
print(Third.__mro__)
prints
(__main__.Third, __main__.First, __main__.Second, object)