In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces what is the meaning of underlining in Python. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Format example function and meaning single underscore beginning _ var is for internal use only. Usually, there is no python interpreter to enforce the end single underscore var_ (suffix) is a convention to avoid naming conflicts with the Python keyword. The beginning of a double underscore, _ _ var, triggers a "noun modifier" when used in a class context. Special methods defined in the _ _ var _ _ python language that are defined by the double underscore beginning and ending are enforced by the python interpreter. Avoid using this method in self-defined attributes to underscore _ as the name of a temporary or meaningless variable ('don't care'). Variables are not used later.
Start with a single underscore: _ var
When it comes to variable and method names, a single underscore prefix has only the agreed meaning
A single underscore is an Python naming convention that indicates that a name is for internal use. It is not usually enforced by the Python interpreter, but is just a hint to the programmer.
End order underscore: var_
The most appropriate name of a variable has been replaced by a keyword. Therefore, a name such as a class or def cannot be used as a variable name in Python. In this case, you can add an underscore to break the naming conflict:
Def object_1 (self, class): pass# run result: SyntaxError: invalid syntaxdef object_1 (self, class_): pass# run result no error reported
Start with a double underscore: _ _ var
The situation is a little different for the properties (including variables and methods) of the Python class that begins with a double underscore.
The double underscore prefix causes the Python interpreter to override property names to avoid naming conflicts in subclasses.
This is also called name modification (name mangling)-the interpreter changes the name of the variable so that conflicts do not occur when the class is extended.
Start and end of double underscore: _ _ var _ _
Python retains the name with double leading and double trailing underscore for special purposes. Such examples are the _ _ init object constructor, or call _ _-which makes an object callable.
It is best to avoid using names that begin and end with double underscores in your programs to avoid conflicts with future Python language changes.
Single underscore: _
A single independent underscore is used as a name to indicate that a variable is temporary or irrelevant, and if this variable is not used later, it can be replaced by _ temporary.
For _ in range (32): print ('Hello, Worldwide') About what the meaning of underlining in Python is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can 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.