mirror of
https://github.com/Hizenberg469/Python-tutorial.git
synced 2026-04-19 23:12:24 +03:00
OOP finished
This commit is contained in:
32
OOP/MRO.py
Normal file
32
OOP/MRO.py
Normal file
@@ -0,0 +1,32 @@
|
||||
#MRO - Method Resolution order
|
||||
|
||||
class A:
|
||||
num = 10
|
||||
|
||||
class B(A):
|
||||
pass
|
||||
|
||||
class C(A):
|
||||
num = 1
|
||||
|
||||
class D(B,C):
|
||||
pass
|
||||
|
||||
print(D.mro())
|
||||
|
||||
# [<class '__main__.D'>,
|
||||
# <class '__main__.B'>,
|
||||
# <class '__main__.C'>,
|
||||
# <class '__main__.A'>,
|
||||
# <class 'object'>]
|
||||
|
||||
# The order of this determined using DFS.
|
||||
|
||||
# A
|
||||
# / \
|
||||
# / \
|
||||
# B C
|
||||
# \ /
|
||||
# \ /
|
||||
# D
|
||||
|
||||
Reference in New Issue
Block a user