In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what is the function of the five kinds of underlining on the basis of Python". In the daily operation, I believe that many people have doubts about the role of the five kinds of underlining on the basis of Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what is the role of the five kinds of underlining on the basis of Python?" Next, please follow the editor to study!
Catalogue
1. Underline after order for example: data_
2. Underline the previous order for example: _ data
3. The first double underscore for example: _ _ data
4. Double underscore: _ _ data__
5. Single underline for example: _
1. Underline after order for example: data_
In fact, this is to prevent duplicate names with system keywords, such as whether there is a keyword class in python.
But I also want to use class as a variable. If I don't deal with it, it will definitely not work. There will be conflicts.
So we can use it by adding _ to class_, later.
I think anyone who knows a little bit about programming can understand this.
2. Underline the previous order for example: _ data
The purpose of this is to tell the programmer that this variable is used internally, not externally, but only internally, just to set a hint, but it can still be used externally. Just tell programmers it's best not to use it externally, and if it's a function, it's the same thing.
See, the system won't prompt it, but it can be forced to write it.
3. The first double underscore for example: _ _ data
This is even simpler, in fact, private variables and functions, subclasses can not be used, as soon as they are used, an error will be reported.
See? it's that simple.
4. Double underscore: _ _ data__
This type is actually called internally by Python, and we don't care how to call it at all, for example:
This is called internally by the system. These functions are used internally when we call other functions. For example, _ _ init _ _ here is a constructor, and we naturally call it internally when we call Person (). For example, similar functions will be called inside the len () we call, as long as we know.
5. Single underline for example: _
1. This is actually a variable that represents a temporary object
For _ in "hongbiao": this has nothing to do with ordinary variables
2. It represents the latest result of running in the program. You can understand it in my last picture.
Note that if the _ here is assigned before, you can no longer take the latest result.
At this point, the study on "what is the role of the five basic underscores of Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.