Practice mode Python

Which algorithm does Python 3 use to compute the method resolution order (MRO) for multiple inheritance?

Correct answer B. C3 linearisation

Explanation

Since Python 2.3, new-style classes use the C3 linearisation algorithm, which preserves the local order of base classes and guarantees that a class appears before its parents. A simple depth-first search could visit a shared base before all its subclasses, which C3 prevents. The result is available as Class.__mro__.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.