Editor

Predict the MRO

Advanced · Predict the output · from Python Multiple Inheritance and MRO: How It Actually Works

From the lesson: Python Multiple Inheritance and MRO: How It Actually Works

Think about how you inherit traits from your parents. You might have your mom's eyes and your dad's sense of humor. You didn't pick one parent - you got traits from both.

Read the lesson

What does this code print? Think about the Method Resolution Order.

class A:
    def who(self):
        return 'A'

class B(A):
    pass

class C(A):
    def who(self):
        return 'C'

class D(B, C):
    pass

d = D()
print(d.who())

Remember: Python follows the MRO, not just the direct parent.

# What does d.who() return?
# Type your prediction as a print statement:
print('C')

More Multiple Inheritance exercises

All Python exercises · 50 practice problems · Object-Oriented Programming quiz