Out of pure curiosity I did the following.
class A:
def x():
print("A.x")
class B:
def x():
print("B.x")
class C(A,B):
pass
C.x()
Which outputs
A.x
Now the behavior I expected was the later superclass's method B.x
executing. Because I thought that methods for A
will be defined first than methods of B
will override them. Instead, A.x
was printed. In fact the first superclass's method .x
was always called. The same behavior was shown with instance methods.
Can anyone explain the way this is happening please?