In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use single underlining in python. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Single underscore (_)
1. In the interpreter: in this case, "_" represents the result of the previous statement executed in the interactive interpreter session. This usage is first adopted by the standard CPython interpreter, and then by other types of interpreters.
> _ Traceback (most recent call last): File ", line 1, in NameError: name'_'is not defined > 42 > _ 42 > 'alrightlighting' If _ else': (''alrightships' > _ 'alrightships'
2. As a name: this is slightly related to the above, and "" is used as a temporary name at this time. In this way, when others read your code, they will know that you have assigned a specific name, but will not use that name again later. For example, in the following example, you may not be interested in the actual value in the loop count, so you can use "".
N = 42for _ in range (n): do_something ()
3. Internationalization: you may have seen "_" used as a function. In this case, it is usually used to implement the function name of translation lookup between internationalized and localized strings, which seems to derive from and follow the corresponding C convention. For example, in the "conversion" section of the Django document, you will see the following code:
From django.utils.translation import ugettext as _ from django.http import HttpResponse def my_view (request): output = _ ("Welcome to my site.") Return HttpResponse (output)
You can find that the usage in scenario 2 and scenario 3 may conflict with each other, so we need to avoid using "" as the temporary name in code blocks that use "" as the internationalized lookup transformation function.
This is the end of the article on "how to use single underline in python". I hope 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.
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.