Amit Kumar : Life Is Learning!

Talk on Python MRO at PyDelhi Meetup 🎙️


Hi there! Today I gave a talk on Python MRO at PyDelhi Meetup at Ramanujan College, Delhi. MRO stands for method resolution order which defines the “class search path” used by Python to search for the right method to use in classes having multi-inheritance. Below is an example

class A:
    def whoami(self):
        print("I am A")

class B(A):
    def whoami(self):
        print("I am B")

class C(A):
    def whoami(self):
        print("I am C")

class D(B, C):
    pass
d = D()
d.whoami()

To get the output of above example Python has a predefined algorithm called as method resolution order, which defines the order in which python would search for the method whoami in the classes from which D inherits. To understand more about the working of mro see the slides of talk.

Motivation for the talk

The motivation behind this talk is my failure to answer some simple mro based question in an interview with a bangalore based startup a month ago. I realized that its one of the basic language features which every Python programmer should be aware of & teaching something is probably the best way to learn something, so is delivering a talk! It’s well said by Albert Einstein:

If you can’t explain it simply, you don’t understand it well enough.

It is always a wonderful experience delivering a talk at PyDelhi Meetup or at any conference, I plan to do more of it in future. I always say this & would say it again, if you like Python or interested in learning then you must attend PyDelhi Meetups. See you on the next meetup ;)

Feel free to reach out to me for any feedbacks or query regarding anything at me [at] iamit [dot] in.