0
0
Pythonprogramming~10 mins

Method Resolution Order (MRO) in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print the method resolution order of class C.

Python
class A:
    pass

class B:
    pass

class C(A, B):
    pass

print(C.[1]())
Drag options to blanks, or click blank then click option'
Amro
Border
Cmethods
Dresolution
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like 'order' or 'methods'.
Trying to access an attribute instead of calling a method.
2fill in blank
medium

Complete the code to define class C that inherits from classes A and B.

Python
class A:
    def greet(self):
        print('Hello from A')

class B:
    def greet(self):
        print('Hello from B')

class C([1]):
    pass
Drag options to blanks, or click blank then click option'
AA
BB, A
CA, B
DB
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order of classes.
Inheriting from only one class instead of both.
3fill in blank
hard

Fix the error in the code to correctly call the greet method from class C.

Python
class A:
    def greet(self):
        print('Hello from A')

class B:
    def greet(self):
        print('Hello from B')

class C(A, B):
    pass

c = C()
c.[1]()
Drag options to blanks, or click blank then click option'
Agreet
Bgreeting
Chello
Dsay_hello
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that do not exist like 'hello' or 'say_hello'.
Trying to call an attribute instead of a method.
4fill in blank
hard

Fill both blanks to create a dictionary showing the MRO of class D and print it.

Python
class X:
    pass

class Y:
    pass

class D([1], [2]):
    pass

print(D.mro())
Drag options to blanks, or click blank then click option'
AX
BY
CA
DB
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated class names like A or B.
Reversing the order of inheritance.
5fill in blank
hard

Fill all three blanks to create a class E that inherits from B and C, and print its MRO.

Python
class B:
    pass

class C:
    pass

class E([1], [2]):
    pass

print([3].mro())
Drag options to blanks, or click blank then click option'
AB
BC
CE
DD
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class names in inheritance or print statement.
Forgetting to call the mro() method.