In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the knowledge of "how do subclasses of python reuse parent class functions". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to reuse parent class functions of python subclasses" can help you solve the problem.
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', 18meme 'unlimited', 10Power9000) print (tea_obj.__dict__) on "how the subclasses of python reuse the functions of the parent class". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.