Python Tutorial - Method Resolution Order MRO

preview_player
Показать описание
Python Tutorial - Method Resolution Order MRO

Рекомендации по теме
Комментарии
Автор

This covers the basic idea of inheritance, but does not cover mro. To understand mro, you need to cover cases where inheritance is different from DFS.

Seehart
Автор

Very nice explanation sir. But I have a doubt, why Python interpreter gives MRO TypeError while inheriting grandparent and then parent.

# Code:
class A:
pass

class B(A):
pass

class C(A, B): # This line gives error
pass

TypeError: Cannot create a consistent method resolution
order (MRO) for bases A, B


Again, thanks for such a good and simple explanation.

abhishekbhardwaj
Автор

class A:
def foo(self):
print("A")

class B(A):
pass

class C(A):
def foo(self):
print("C")

class D:
def foo(self):
print("D")

class E(B, C, D):
pass

E().foo()

What will be displayed as a result of executing this code?
Try to work it out in your mind.

ceeggtevfrhejchdj
Автор

this video doesn't explain MRO well. It only covers basic case, you won't still know how MRO works after this video in real situation.

waddragon