Method Resolution Order (MRO) in Python
Which three statements about the Method Resolution Order (MRO) in Python are true? (Choose three.)
Quick Answer
The answer is that in diamond inheritance, the topmost base class is visited last. This is correct because Python’s Method Resolution Order (MRO) follows the C3 linearization algorithm, which ensures a consistent, monotonic search path through the inheritance hierarchy. The algorithm guarantees that a child class is always checked before its parents, and when multiple parent classes share a common ancestor, that ancestor is only visited after all its subclasses have been exhausted. On the Certified Associate Python Programmer PCAP exam, this concept often appears in multiple-choice questions testing your understanding of how Python resolves method calls in complex inheritance, with a common trap being the assumption that Python uses a simple depth-first search. A reliable memory tip is to remember the MRO mantra: “child before parent, and the topmost common ancestor comes last,” which you can verify at any time by inspecting a class’s `__mro__` attribute.
⚠ Common exam trap
Python Institute often tests the misconception that the MRO only applies to methods, when in fact it governs all attribute lookups, including data attributes and descriptors.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The MRO can be viewed using the __mro__ attribute.
Option A is correct because Python exposes the computed MRO as a tuple through the __mro__ attribute on every class (and also via ClassName.mro()), so it can be inspected directly. Option B is correct because since Python 2.3 the MRO is computed using the C3 linearization algorithm, which guarantees a consistent, monotonic ordering that respects local precedence and the order of base classes. Option D is correct because in a diamond hierarchy C3 linearization places the most derived class first and the common topmost base class (e.g., object) last, after all intermediate classes. Option C is not correct because the MRO governs attribute lookup in general, including non-method attributes such as data descriptors and class variables, not just methods. Option E is not correct because the MRO is computed once when the class is created and is stored in the class's __mro__; altering the class hierarchy at runtime does not recompute or allow modification of an existing class's MRO.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
The MRO can be viewed using the __mro__ attribute.
Why this is correct
The __mro__ attribute exposes the resolved lookup order as a tuple of classes, letting you inspect exactly how Python will search for methods and attributes. It satisfies the scenario's need to view the MRO directly on a class.
- ✓
MRO is determined by the C3 linearization algorithm.
Why this is correct
C3 linearization builds a consistent, monotonic order by merging each class's parents' MROs while preserving local precedence and inheritance hierarchy. This satisfies the stem's requirement that MRO follows a defined algorithm, guaranteeing deterministic resolution for diamond inheritance without contradicting earlier orderings.
- ✗
The MRO is only used for methods, not attributes.
Why it's wrong here
MRO applies to attribute lookup generally, resolving both methods and data attributes along the linearised class hierarchy. It is tempting because method resolution is the common case, but instance and class attributes follow the same C3 linearisation, so restricting MRO to methods misstates its scope.
- ✓
In diamond inheritance, the topmost base class is visited last.
Why this is correct
Python’s C3 linearisation guarantees each class appears after its subclasses, so in a diamond hierarchy the shared topmost base is deferred until both branches are exhausted. This satisfies the stem’s requirement that the common ancestor be visited last, after the intermediate classes inheriting from it.
- ✗
The MRO can be changed by modifying the class hierarchy at runtime.
Why it's wrong here
MRO is computed once when a class is created and cached in __mro__; altering base classes afterwards does not recompute it, and Python raises errors for inconsistent hierarchies. It is tempting because dynamic class modification is possible, but the linearisation itself is fixed at class definition time.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCAP question from scratch — 421 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
2 more ways this is tested on PCAP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Which THREE statements about the Python method resolution order (MRO) are true? (Select exactly 3.)
hard- A.The MRO is determined at runtime when a method is called.
- ✓ B.The MRO of a class can be viewed using the __mro__ attribute.
- ✓ C.C3 linearization is the algorithm used for MRO in Python 3.
- D.Python uses a depth-first left-to-right algorithm for MRO.
- ✓ E.super() uses the MRO to determine which method to call.
Why B: The `__mro__` attribute on a class returns a tuple of classes in the exact order that Python uses to resolve methods and attributes. This attribute is computed at class definition time using the C3 linearization algorithm, and it provides a direct, read-only view of the resolution order for that class.
Variation 2. Refer to the exhibit. What is the output? (Note: actual MRO may vary; choose the one that matches Python 3 C3 linearization.)
hard- A.(<class '__main__.D'>, <class '__main__.B'>, <class '__main__.C'>, <class '__main__.A'>)
- ✓ B.(<class '__main__.D'>, <class '__main__.B'>, <class '__main__.C'>, <class '__main__.A'>, <class 'object'>)
- C.(<class '__main__.D'>, <class '__main__.C'>, <class '__main__.B'>, <class '__main__.A'>, <class 'object'>)
- D.(<class '__main__.D'>, <class '__main__.A'>, <class '__main__.B'>, <class '__main__.C'>, <class 'object'>)
Why B: Python 3 uses C3 linearization to compute the Method Resolution Order (MRO). For class D inheriting from B and C, which both inherit from A, the MRO is D, B, C, A, object. This satisfies the monotonicity and local precedence order: B comes before C (as per D's bases), and A is last among the user-defined classes, with object always appended.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.