image block
2534 Views 151 Comments
Hi guys!
Today I'm going to discuss with u the magic symbol like underscore. Why it's magical? It's a reasonable question. But what will be, if I will tell you, that this symbol has a big role on programming and in Python at all? Don't believe me? Just let's see!
And actually, I have 7 things which I hope will prove you that this symbol is useful.

7 reasons why we are using underscore in Python

1. Under underscore is saving last expression value

And what it can be, you can ask. I will explain.
The CPython interpreter is caching the last value. For example :
>>> 10
>>> _
>>> _*10
>>> _
Also it can be implemented from variable :
>>> a=10
>>> _
>>> a
>>> _
But it's just a little thing why we are using it, let's move on on the second reason.

2. Underscore is using for ignoring values

Yes, yes! You heard right!
Underscore symbol is using for ignoring not important values on our code. Let's review few examples.
Let's imagine that we need to make the cycle on our code, but we don't care about index inside of it. We can easy to do it.
>>> for _ in range(5):
...     pass
Instead the pass command we can paste any action what we need.
We can ignore values during the assignment of variables.

>>> a, _, b = (1,2,3)
>>> print (a,b)
1 3
Or ignore a lot of values (this is called "Extended Unpacking" but this function is availible from python 3.6+)
>>> a, *_, b = (1,2,3,4,5)
>>> print (a,b)
1 5

3. Underscore is using for avoiding the name conflicts

The underscore symbol in the end of variables is using for avoiding the conflict of names inside one big code.
For example, you have variable price which is using in your class, but also you need to have the same variable with which one you will work, inside some function. So, you can easily to call new variable like price_ which will have totally different space on the memory and not affect on origin one.
Now, let's move on to more reasonable things.

4. Underscore is using for making private objects

Yes, underscore at the beginning of the name of the object (variable, function, class), is telling that this object is private for the specific place.
Private, it's mean that this object will not be imported with all other elements.
For example, if I will create two files: and
In the I will call two variables :
val1 = 1
_val2 = 2
And in, I just will try to import them :
from test2 import *
And I will see, that on my I will have only varialbe val1, because _val2 variable will be ignored durring import.
This is can be implemented for any type of object.
class : class _Classname():
function : def _functionname():
variable : _variablename=0

5. The name mangling technique via underscore

At first, let's understand what is name mangling.
Name mangling is a technique used to solve problems caused by the need to resolve unique names. This technique is using on all modern programming languages and Python one from them.
In other words, if we want to restrict objects inside some class, double underscore at the beginning of name will help us. Let's see the example.
>>> class A():
...     def __init__(self):
...             self.var1 = 1
...             self._var2 = 2
...             self.__var3 = 3
>>> classA=A()
>>> dir(classA)
['_A__var3', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_var2', 'var1']
We have created the class with three variables and after calling it, printed all objects inside class.
Now we see nothing strange with first variable var1 and second one _var2. They can be use like as usual, but let's have a look on third variable __var3.
Object of this variable have a difference with other ones. From "dir" function we see, that this variable can be used only from this class and cannot be imported outside.
For example let's try to use them.
>>> classA.var1
>>> classA._var2
>>> classA.__var3
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'A' object has no attribute '__var3'
>>> classA._A__var3
That's what I'm talking about. We can use this variable only in case, when calling it from class object, like we made before.

6. Using underscore for readability

From Python 3.6, appeared additional function for underscore, which gives more comfortable usability.
I don't want to make a big attention on it, so let's review examples:
>>> dec_base=1_000_000
>>> print(dec_base) 
>>> bin_base=0b_1111_0000
>>> print(bin_base)
>>> hef_base=0x_1234_abcd
>>> print(hef_base) 

7. The underscore symbol for defining special methods

What are these methods? They're special methods that you can define to add special methods to your classes. They're always surrounded by double underscores (e.g. __init__ or __del__).
These methods have functions which are made classes more flexible and easier to use. All of them are well documented on official documentation and if you want to know more about them, you can do this by this link Python.

I I hope something from this information was a novelty and you learned something new for yourself. But today that's all from my side.

Wish you good luck!
- Kostia


  1. where to get viagra <a href="">walgreens pharmacy viagra 100mg cost</a> how much is viagra at cvs

  2. viagra multiple cum <a href="">viagra replacement over the counter</a> 20 mg viagra and meth

  3. viagra substitute prescption <a href="">best herbal viagra</a> viagra substitute

  4. how to order viagra <a href="">can you take cialis and viagra together</a> viagra cost per 100mg pill

  5. yohimbe 451 vs viagra <a href="">new viagra model</a> measuring viagra sales

  6. viagra without a doctor prescription in usa <a href="">can i buy viagra without prescription</a> viagra prescription online usa

  7. tramadol with viagra <a href="">homemade viagra watermelon</a> buying viagra online canada

  8. best place to buy viagra without prescription <a href="">non prescription viagra substitute</a> how many days do you have to fill a prescription for viagra

  9. viagra structure <a href="">viagra online pharmacy</a> what is the brand name for the generic drug for viagra

  10. generic viagra without prescription <a href="">is a prescription needed for viagra or cialis</a> buying viagra without prescription

  11. viagra women eat <a href="">viagra meme</a> how much does viagra cost?

  12. do i need a prescription for cialis or viagra <a href="">fake viagra prescription label</a> cheapest viagra with prescription

  13. viagra dosnt work now what <a href="">viagra vs cialis vs levitra reviews</a> can you get viagra without going to the doctor?

  14. purchase viagra without prescription <a href="">get viagra prescription</a> is a prescription needed for viagra

  15. viagra home delivery <a href="">viagra usage</a> viagra roman

  16. how to get prescription for viagra <a href="">how do i get a prescription for viagra</a> viagra without a doctor prescription walmart

  17. viagra non perspiration <a href="">viagra cum milking</a> canadian drugs viagra

  18. viagra online prescription <a href="">order generic viagra usa no prescription</a> do i need a prescription for cialis or viagra

  19. buy viagra no prescription <a href="">viagra without doctor prescription reviews</a> viagra prescription in europe

  20. can you take sildenafil with atorvastation <a href="">supplements with sildenafil</a> generic sildenafil citrate 50mg us pharmacys

  21. sildenafil citrate tablets 100mg reviews <a href="">sildenafil tablets are for what</a> generic viagra sildenafil citrate reviews

  22. why does viagra cost so much <a href="">get a prescription for viagra</a> cfnm viagra picnic

  23. sildenafil withdrawal symptoms <a href="">canada sildenafil</a> trying sildenafil for the first time

  24. sildenafil 100mg expiration <a href="">sildenafil mexico pharmacy</a> pfizer viagra sildenafil citrate

  25. generic sildenafil 100mg tabs <a href="">medication similar to sildenafil</a> who sells sildenafil off the shelf

  26. blue vision caused by sildenafil <a href="">sildenafil prices walgreens</a> low dose sildenafil

  27. viagra and alcohol consumption <a href="">viagra time to work</a> san diego viagra cialis

  28. alcohol and viagra <a href="">cialis vs viagra vs levitra</a> can viagra cause a stroke

  29. sildenafil 25 mg uses <a href="">private prescription sildenafil</a> cure for sildenafil

  30. viagra bad side effects <a href="">new port richey fl pharmacy viagra</a> viagra vs levitra vs cialis

  31. is headachs commom when taking sildenafil <a href="">sildenafil troche dosage</a> sildenafil 100mg coupon 10 tablet

  32. where to buy viagra in store <a href="">viagra for daily use</a> trimix and viagra

  33. where to buy sildenafil citrate 20 mg <a href="">preis sildenafil axapharm</a> sildenafil citrate liquid form for research

  34. sildenafil generico farmacias del ahorro <a href="">sildenafil side effects alcohol</a> revatio sildenafil generic

  35. cancun viagra la isla <a href="">will va medical care cover viagra</a> viagra online cheap

  36. viagra fname en argentina venta <a href="">what to use to enhance viagra</a> which is better - cialis or viagra

  37. new viagra commercial actress name <a href="">real viagra without a doctor prescription usa</a> viagra action

  38. why viagra doesnt work <a href="">buying generic viagra in canada</a> 90 viagra pills

  39. how to get cialis without a doctor <a href="">cialis vs viagra vs levitra</a> buy cialis cheap prices fast delivery

  40. how much is a cialis pill <a href="">women taking cialis</a> 60 mg cialis

  41. viagra vs cialis vs levitra forum <a href="">wholesale cialis 20 mg</a> 30 day voucher for free cialis

  42. dangers of cialis <a href="">how long does cialis 20 mg last</a> what can i take to enhance cialis

  43. mexican cialis <a href="">buy cialis canada pharmacy</a> what happens if a girl takes cialis

  44. cialis vs viagra vs kamagra <a href="">cialis what to expect</a> when cialis doesn t work

  45. cialis effective time <a href="">ed forum cialis</a> cialis daily use 5mg

  46. does cialis increase sensitivity <a href="">discount cialis prescriptions</a> cialis 5mg vs viagra

  47. when can we buy cialis generic <a href="">cheapest place to buy cialis</a> cialis online coupon code

  48. cialis instructions <a href="">cialis works</a> cialis blurred vision temporary

  49. stree overlord exceed viagra and cialis <a href="">order cheap cialis</a> when cialis doesnt work

  50. cialis next day delivery usa <a href="">why no generic cialis</a> what is the ingredients in cialis

  51. koi cbd wholesale cbd oil <a href="">cbd oil for leukemia</a> cbd oil softgels

  52. how long before cbd oil works <a href="">vet recommended cbd oil for dogs</a> best cbd oil for pain and anxiety

  53. cbd oil for pain dosage <a href="">reviews cbd oil for pain</a> cbd oil dosage degenerative disc disease

  54. cbd vs hemp oil <a href="">cbd oil laws in kentucky</a> can cbd oil help with anxiety

  55. cbd oil biotech cream sold by diamond cbd <a href="">cbd pills vs oil</a> is cbd oil harmful to liver or brain

  56. how much cbd oil to use for pain <a href="">cbd oil cannabidiol for pain</a> cbd oil for pain relief lotion

  57. can i fly overseas with cbd oil <a href="">cbd oil dose for schizophrenia</a> cbd oil by locust

  58. origin of marys cbd oil <a href="">does full spectrum hemp oil have cbd</a> hemp oil same as cbd

  59. is cbd oil effective for pain <a href="">cbd oil and joint pain</a> cbd oil for pain

  60. does cbd oil stay in your system <a href="">coconut oil and cbd oil</a> cbd oil for pain amazon

  61. why take cbd oil <a href="">can you eat cbd vape oil</a> daily choice cbd oil

  62. xname cbd oil reviews <a href="">best cbd oil pain tmj and migraines</a> cbd oil for self-care

  63. can cbd oil help with anxiety <a href="">what is georgia's law on cbd oil</a> cbd vs hemp oil for pain

  64. best value cbd oil in plano <a href="">does cbd oil show up on blood test</a> xname haa cbd oil

  65. tramadol and cbd oil <a href="">does cbd oil give you energy</a> can cbd oil cause constipation or urinary retention

  66. releaf cbd oil <a href="">does cbd oil thin the blood</a> cbd oil from switzerland

  67. best cbd oil reviews for arthritis <a href="">cost of cbd oil in florida</a> cbd oil and liver

  68. cbd mct oil benefits <a href="">cbd oil dosage</a> cbd oil biotech

  69. who sells cbd oil in mn <a href="">cbd oil for anxiety reviews</a> sisters of the valley cbd oil dosage

  70. cbd oil where can i buy it in mississippi <a href="">truth about cbd oil</a> vape pen cbd oil model ah9219

  71. prozac and cbd oil <a href="">cbd oil ingestion</a> cbd oil dab

  72. 250mg or 1500mg cbd oil <a href="">purekana cbd oil review</a> cbd oil interaction with lisinopril

  73. top cbd vape oil <a href="">cbd oil sex drive</a> cbd oil for sale wilmington nc

  74. can you smoke cbd oil in a vape <a href="">cbd oil a1c</a> cbd oil illegal states

  75. ac dc cbd oil + co2 <a href="">b cbd oil</a> cbd oil 1125 mg compared to pure 750 mg

  76. cbd xname hemp oil capsules <a href="">cbd oil side effects on liver</a> cbd oil studies cnn

  77. anxiety and cbd oil <a href="">pet cbd oil for dogs</a> cbd oil brookings sd

  78. cbd oil benefits chart <a href="">benefits of taking cbd oil</a> cbd oil full spectrum for copd

  79. rick simpson cbd oil <a href="">plus cbd oil gold</a> buy cbd oil for sleep problems

  80. is cbd oil legal for teachers in maryland <a href="">cbd oil lupus</a> cbd oil in mn

  81. cbd oil business <a href="">7 cbd oil</a> cbd oil in wisconsin sold at vape stores

  82. cbd oil and macular degeneration <a href="">bessemer michigan cbd oil for cancer</a> can cbd oil cause nausea

  83. does the good apple sell cbd oil <a href="">walgreen's stock cbd oil</a> is thc in cbd oil

  84. can cbd oil be put in ear <a href="">cbd oil testimonials</a> cbd oil cause inflammation

  85. cbd oil where to find <a href="">cbd oil and blood pressure meds</a> medical research on cbd oil

  86. cbd oil for md <a href="">where to buy cbd oil in oklahoma</a> cbd tincture vs oil

  87. jolly green oil cbd review <a href="">cbd oil hemp oil</a> make cbd oil for chronic pain

  88. my website <a href="">take a look at the site here</a> Read Full Report

  89. this link <a href="">you can try these out</a> secret info

  90. read review <a href="">view website</a> useful link

  91. right here <a href="">click here</a> find more info

  92. Read More <a href="">visit</a> find this

  93. visit homepage <a href="">look at here now</a> look what i found

  94. great site <a href="">Check Out</a> click for info

  95. visit this link <a href="">the original source</a> Extra resources

  96. Continued <a href="">Recommended Site</a> content

  97. see it here <a href="">Discover More</a> continue reading this

  98. basics <a href="">why not try this out</a> read what he said

  99. home page <a href="">top article</a> view

  100. try this out <a href="">pop over to this website</a> This site

  101. look what i found <a href="">this link</a> click over here now

  102. Going Here <a href="">Read This</a> take a look at the site here

  103. click here to investigate <a href="">sites</a> address

  104. super fast reply <a href="">visit</a> you could look here

  105. view publisher site <a href="">click to read</a> hop over to this website

  106. Check Out Your URL <a href="">go to the website</a> this website

  107. check this site out <a href="">their explanation</a> pop over to this website

  108. the full report <a href="">you can look here</a> discover this info here

  109. investigate this site <a href="">see here now</a> Home Page

  110. see this site <a href="">read this</a> this website

  111. this contact form <a href="">her explanation</a> super fast reply

  112. hop over to this site <a href="">read more here</a> click here for more

  113. from this source <a href="">click resources</a> Check This Out

  114. you could try these out <a href="">Recommended Reading</a> useful reference

  115. you could check here <a href="">breaking news</a> Look At This

  116. go to website <a href="">on the main page</a> websites

  117. visit this site <a href="">more info here</a> enquiry

  118. Learn More <a href="">more info here</a> try here

  119. click here now <a href="">Resources</a> see post

  120. my website <a href="">click this link here now</a> i thought about this

  121. find out <a href="">on the main page</a> click this

  122. look at this web-site <a href="">content</a> address

  123. other <a href="">Learn More</a> index

  124. will cbd oil help pancreatitis in dogs <a href="">cbd oil stands for</a> cbd oil near placerville ca

  125. how to use viagra for best results <a href="">viagra shot</a> what is generic viagra

  126. female viagra name <a href="">information on viagra for men</a> dosages of viagra sildenafil revatio

  127. where do you get cbd oil <a href="">gold cbd oil concentrate</a> can cbd oil he

  128. where to buy real viagra <a href="">viagra and diflucan interactions</a> injectable viagra

  129. cbd oil how it works <a href="">cbd oil for stress and sleep</a> cbd oil dispensary

  130. viagra incest creampie <a href="">active ingredient in viagra</a> viagra sin receta medica

  131. ultracell full spectrum hemp cbd oil <a href="">will cbd oil kill cancer</a> should cbd oil be refrigerated

  132. cannabidiol life cbd oil sales <a href="">ananda professional cbd oil</a> xname full spectrum cbd oil

  133. viagra and red wine <a href="">massive hard on from viagra</a> viagra and marijuana

  134. cbd oil 100 mg <a href="">grandma's hemp full spectrum cbd oil amazon</a> whole greens cbd oil free trial

  135. healthy man viagra scam <a href="">levitra vs cialis vs viagra</a> buy real viagra online cheap

  136. viagra cialis online <a href="">cheap viagra pills online</a> can viagra cause lockjaw

  137. honey b cbd oil <a href="">cbd oil for sleep</a> best cbd oil gummies

  138. best way t o take viagra <a href="">sub for viagra</a> viagra low blood pressure

  139. can i buy cbd oil in florida <a href="">could cbd oil help with aspiration</a> cbd oil snake oil

  140. produit viagra sans ordonnance <a href="">libido max vs viagra</a> viagra and headache

  141. does cbd oil work for psoriasis <a href="">does cbd oil interact with methotrexate</a> c4 health labs cbd oil

  142. viagra for the brain <a href="">viagra in women</a> viagra and thyroid medication

  143. ow much cbd oil to give to my dog <a href="">can i put cbd oil in my ear</a> nu way vape cbd oil muscle shoals

  144. get cialis now <a href="">cialis time</a> cialis grapefruit interaction

  145. how to use cialis <a href="">cialis single dose</a> cialis in slovakia

  146. where to buy cbd oil in georgia <a href="">cbd oil shingles</a> cbd oil in store central al

  147. how to get free cialis <a href="">guy fucks on cialis</a> compare lisinipril and cialis

  148. what is the maximum dosage of cialis <a href="">cialis stroke</a> how often can you take 20 mg of cialis

  149. cbd oil dosage for migraines <a href="">cbd oil in nj</a> cbd hemp oil legal in all 50 states



  152. Leave a Comment