# How to use multiple inheritance and method resolution order (MRO) in Python

11 views
asked Feb 12, 2018

class A:
def m(self):
print("class A: m(self)")

class B(A):
def m(self):
print("class B(A): m(self)")

class C(A):
def m(self):
print("class C(A): m(self)")

class D(B, C):
def m(self):
print("class D(B, C): m(self)")

do = D()
B.m(do)

'''
run:

class B(A): m(self)

'''

answered Feb 12, 2018 by
class A:
def m(self):
print("class A: m(self)")

class B(A):
def m(self):
print("class B(A): m(self)")

class C(A):
def m(self):
print("class C(A): m(self)")

class D(B, C):
def m(self):
print("class D(B, C): m(self)")

do = D()
C.m(do)

'''
run:

class C(A): m(self)

'''

answered Feb 12, 2018 by
class A:
def m(self):
print("class A: m(self)")

class B(A):
def m(self):
print("class B(A): m(self)")

class C(A):
def m(self):
print("class C(A): m(self)")

class D(B, C):
def m(self):
print("class D(B, C): m(self)")

do = D()
A.m(do)

'''
run:

class A: m(self)

'''

answered Feb 12, 2018 by
class A:
def m(self):
print("class A: m(self)")

class B(A):
def m(self):
print("class B(A): m(self)")

class C(A):
def m(self):
print("class C(A): m(self)")

class D(B, C):
def m(self):
print("class D(B, C): m(self)")
A.m(self)
B.m(self)
C.m(self)

do = D()
do.m()

'''
run:

class D(B, C): m(self)
class A: m(self)
class B(A): m(self)
class C(A): m(self)

'''

answered Feb 12, 2018 by
class A:
def m(self):
print("class A: m(self)")

class B(A):
def m(self):
print("class B(A): m(self)")
A.m(self)

class C(A):
def m(self):
print("class C(A): m(self)")
A.m(self)

class D(B, C):
def m(self):
print("class D(B, C): m(self)")
B.m(self)
C.m(self)

do = D()
do.m()

'''
run:

class D(B, C): m(self)
class B(A): m(self)
class A: m(self)
class C(A): m(self)
class A: m(self)

'''

answered Feb 12, 2018 by