mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Clarify "Method Resolution Order" (#4687)
This commit is contained in:
parent
f472504d58
commit
73584a2e27
@ -876,7 +876,8 @@ if __name__ == '__main__':
|
|||||||
if type(sup) is Superhero:
|
if type(sup) is Superhero:
|
||||||
print('I am a superhero')
|
print('I am a superhero')
|
||||||
|
|
||||||
# Get the Method Resolution search Order used by both getattr() and super()
|
# Get the "Method Resolution Order" used by both getattr() and super()
|
||||||
|
# (the order in which classes are searched for an attribute or method)
|
||||||
# This attribute is dynamic and can be updated
|
# This attribute is dynamic and can be updated
|
||||||
print(Superhero.__mro__) # => (<class '__main__.Superhero'>,
|
print(Superhero.__mro__) # => (<class '__main__.Superhero'>,
|
||||||
# => <class 'human.Human'>, <class 'object'>)
|
# => <class 'human.Human'>, <class 'object'>)
|
||||||
@ -958,8 +959,7 @@ class Batman(Superhero, Bat):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sup = Batman()
|
sup = Batman()
|
||||||
|
|
||||||
# Get the Method Resolution search Order used by both getattr() and super().
|
# The Method Resolution Order
|
||||||
# This attribute is dynamic and can be updated
|
|
||||||
print(Batman.__mro__) # => (<class '__main__.Batman'>,
|
print(Batman.__mro__) # => (<class '__main__.Batman'>,
|
||||||
# => <class 'superhero.Superhero'>,
|
# => <class 'superhero.Superhero'>,
|
||||||
# => <class 'human.Human'>,
|
# => <class 'human.Human'>,
|
||||||
|
Loading…
Reference in New Issue
Block a user