In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what is the use of Python underlining, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. Used in the Python interpreter to represent the result of the last execution
Even if you don't use Python for programming, you can use it as an intelligent calculator, and the underscore saves the results of the last calculation, which is quite convenient for calculation:
> 4 + 37 > > _ 7 > > _ + 29 > > a = 10 > _ 92, an independent underscore in the code indicates that this variable is not important
An independent underscore, it is also a variable name, but it is special, when you use an underscore as a variable name, it means you tell everyone that this variable is not important, only occupies a place, can be ignored, and will not be used later.
Of course, it's just a convention, and you can do it if you don't follow it. After all, you can get the value of this variable by underlining it later.
For I, _ in [(1,2), (3,4)]: print (I)
The above code indicates that we only need the first tuple in the list, and the second one is actually assigned to the underscore, although you can get the value later through the sliding line, but you are strongly advised not to do so, which is a violation of the convention.
3. The method of beginning and ending of double underscore is a magic method.
For example, the common'_ _ init__','_ _ dict__','_ _ dir__','_ _ doc__','_ eq__' and so on.
You can read how to write amazing Python classes.
4. as part of the middle of the variable name
Compared to hump naming, this is called serpentine naming, such as user_name.
5. As a part of the number, it is easier to read > 10000000 10000000 > 1" 28000050000000 = = 1280500000 True is all the content of this article "what is the use of Python underlining?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.