Usage of the Underscore(_) in Python?
Usage of the Underscore(_) in Python and how to use it This is a continued story of my previous post Star in Python. In this article, we will know about the usage of underscore in Python. If you do not use a variable then you can name it as underscore. Here we have not used the values of the dictionary therefore no need to assign that to a named variable, underscore we have used to denote the values of the dictionary. This is a best practice. Underscore plays a significant part in OOP. To define a private method To define in-built under methods Under PEP8 guideline variable names should be delimited with underscores. In the terminal or command prompt to access the last output of the operation you can use the underscore. Photo by the author. Usage of the Underscore(_) in Python?
As a placeholder of variable
>>> =
>>>
...
:
:
Although this is not such an excellent example, hope you got the point. In object-oriented programming
Private method
_
prefix is used.
>>> :
... :
... pass
Protected method
>>> :
... :
... pass
Dunder method
>>> :
... :
... pass
Variable name delimiter
Access last executed result in command prompt
>>> 4 + 3
7
>>>
7
ipython
takes it to the next level with number-based access. Separate digits for readability
>>> 1_00_000
100000
>>> 3_25_50_000 == 32550000
True
Related Articles