In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to convert python into a private attribute. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
1. Add an underscore before the property or method name to indicate that the property or method is used only in the class.
2. You can manually call _ age to obtain the age attribute. A more stringent method is to add two underscores _ _ before the attribute or method, which cannot be obtained by manually calling the attribute.
Example
Class Student: def _ init__ (self, name, sex, age): self.name = name self.sex = sex self._age = age def run (self): print ("I am {0}, I can run" .format (self.name) def jump (self): print ("I am {0}, {1}) Can jump ".format (self.name, self.sex) xiao_ming = Student (" Xiaoming "," male ", 19) xiao_hong = Student (" Xiao Hong "," female ", 20) xiao_ming.run () xiao_hong.jump () # call private attribute, you can fall, but please follow the convention rule print (xiao_hong._age) on" how to convert python into private attribute "this article ends here. Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.