In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the python subclass how to reuse the parent class function, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
1. Call functions under a certain class directly according to the name, rather than relying on inheritance relationships.
2. Call the method mentioned by the parent class, that is, strictly rely on the inheritance relationship. Calling super results in a special object that refers to the mro of the class that initiated the property search and finds the property in the parent class of the current class.
Example
Class people: def _ _ init__ (self,name,age,sex): self.name=name self.age=age self.sex=sex class boss (people): def _ _ init__ (self,name,age,sex,level,salary): # the following two lines of code have the same effect: super (boss,self). _ _ init__ (name,age,sex) super (). _ _ init__ (name,age Sex) self.level = level self.salary=salary print (boss.mro ()) print ('='* 50) tea_obj=boss ('capitalist', 18'no limit', 10 'Magi 9000) print (tea_obj.__dict__) Thank you for reading this article carefully I hope the article "how to reuse the parent function of python subclasses" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.