Get the App
SLTechnology News&Howtos  ›  Development  › 

What's the use of Python underlining?

Shulou Source: shulou.com Published: 2022-06-02 05:03:22 10月01日 Update

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!

Tags: Underscores variables articles important code content can be passed method result independent convention special convention not much bit representative but just mostly common Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno Shulou Tech Info Linux Shulou Technology