In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to understand the inheritance of python classic classes and new classes, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
Example 1:
Class a:
Def p (self):
Print "aaaaaaaaaaaa"
Class b (a):
Pass
Class c (a):
Def p (self):
Print "cccccccccccc"
Class d (bmaine c):
Pass
D = d ()
D.P ()
# the result is aaaaaaaaaaa
Example 2:
Class a:
Def p (self):
Print "aaaaaaaaaaaa"
Class b (a):
Pass
Class c (a):
Def p (self):
Print "cccccccccccc"
Class d (c) b):
Pass
D = d ()
D.P ()
# the result is cccccccccccc
Example 3:
Class a:
Pass
Class b (a):
Pass
Class c (a):
Def p (self):
Print "cccccccccccc"
Class d (bmaine c):
Pass
D = d ()
D.P ()
# the result is cccccccccccc
Conclusion: it can be seen from the above that, corresponding to the classical classes that do not inherit object, the case search method adopts the idea of depth first.
As shown in the above example, the p method of D first finds out whether d itself has the method, if not, it goes up to the first parent class to see if it has the method, and if not, to find out whether the first parent class has the method until the root.
If none, the root is found from the second parent class.
Example 4:
Class a (object):
Def p (self):
Print "aaaaaaaaaaaa"
Class b (a):
Pass
Class c (a):
Def p (self):
Print "cccccccccccc"
Class d (bmaine c):
Pass
D = d ()
D.P ()
# the result is cccccccccccc
Conclusion: for the new class inherited from object, the breadth-first idea is adopted in the case search method.
As shown in the above example, the p method of D first finds whether d itself has the method, if not, it goes up to the first parent class to see if it has the method, and if not, it finds out whether the other parent classes of the same level have the method, and then searches for the parent class at a higher level after searching the siblings, until the root.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.