I’m not a native speaker. Sorry for my english. Please understand. The (_) is special in Python. underscore While the (_) is used for just snake-case variables and functions in most languages (Of course, not for all), but it has special meanings in Python. If you are python programmer, , like syntax may be familiar. underscore for _ in range(10) __init__(self) This post will explain the about when and how use the (_) and help you understand it. underscore There are 5 cases for using the in Python. underscore For storing the value of last expression in interpreter. For ignoring the specific values. (so-called “I don’t care”) To give special meanings and functions to name of vartiables or functions. To use as ‘Internationalization(i18n)’ or ‘Localization(l10n)’ functions. To separate the digits of number literal value. Let’s look at each case. When used in interpreter The python interpreter stores the last expression value to the special variable called ‘_’. This feature has been used in standard CPython interpreter first and you could use it in other Python interpreters too. >>> 1010>>> _10>>> _ * 330>>> _ * 20600 For Ignoring the values The is also used for ignoring the specific values. If you don’t need the specific values or the values are not used, just assign the values to . underscore underscore _# Ignore a value when unpacking_x, _, y = (1, 2, 3) # x = 1, y = 3 x, *_, y = (1, 2, 3, 4, 5) # Ignore the multiple values. It is called "Extended Unpacking" which is available in only Python 3.x # x = 1, y = 5 _# Ignore the index_for _ in range(10):do_something() for _, val in list_of_tuple:do_something() # Ignore a value of specific location Give special meanings to name of variables and functions The may be most used in ‘naming’. The PEP8 which is Python convention guideline introduces the following 4 naming cases. underscore **_single_leading_underscore**This convention is used for declaring variables, functions, methods and classes in a module. Anything with this convention are ignored in . However, of course, Python does not supports so we can not force somethings private ones and also can call it directly from other modules. So sometimes we say it “weak internal use indicator”. private from module import * truly private, _internal_name = 'one_nodule' # private variable_internal_version = '1.0' # private variable class _Base: # private class_hidden_factor = 2 # private variable def \_\_init\_\_(self, price): self.\_price = price def \_double\_price(self): # private method return self.\_price \* self.\_hidden\_factor def get\_double\_price(self): return self.\_double\_price() **single_trailing_underscore_**This convention could be used for avoiding conflict with Python keywords or built-ins. You might not use it often. Tkinter.Toplevel(master, class_='ClassName') # Avoid conflict with 'class' keyword list_ = List.objects.get(1) # Avoid conflict with 'list' built-in type **__double_leading_underscore**This is about syntax rather than a convention. will mangle the attribute names of a class to avoid conflicts of attribute names between classes. (so-called “mangling” that means that the compiler or interpreter modify the variables or function names with some rules, not use as it is) The mangling rule of Python is adding the “_ClassName” to front of attribute names are declared with That is, if you write method named “__method” in a class, the name will be mangled in “_ClassName__method” form. double underscore double underscore. class A:def _single_method(self):pass def \_\_double\_method(self): # for mangling pass class B(A):def __double_method(self): # for manglingpass Because of the attributes named with will be mangled like above, we can not access it with “ClassName.__method”. Sometimes, some people use it as like real private ones using these features, but it is not for private and not recommended for that. For more details, read . double underscore Python Naming **__double_leading_and_trailing_underscore__**This convention is used for special variables or methods (so-called “magic method”) such as , . These methods provides special syntactic features or does special things. For example, indicates the location of Python file, is executed when expression is excuted. A user of course can make custom special method, it is very rare case, but often might modify the some built-in special methods. (e.g. You should initialize the class with that will be executed at first when a instance of class is created.) __init__ __len__ __file__ __eq__ a == b __init__ class A:def __init__(self, a): # use special method '__init__' for initializingself.a = a def \_\_custom\_\_(self): # custom special method. you might almost do not use it pass As Internationalization(i18n)/Localization(l10n) functions It is just convention, does not have any syntactic functions. That is, the underscore does not means , and it is just a convention that binds the to variable has been from C convention.The built-in library which is for uses this convention, and Django which is Python web framework supports also introduces and uses this convention. i18n/l10n i18n/l10n underscore gettext i18n/l10n i18n/l10n # see official docs : import gettext https://docs.python.org/3/library/gettext.html gettext.bindtextdomain('myapplication','/path/to/my/language/directory')gettext.textdomain('myapplication')_ = gettext.gettext # ... print(_('This is a translatable string.')) To separate the digits of number literal value This feature was added in Python 3.6. It is used for separating digits of numbers using for readability. underscore dec_base = 1_000_000bin_base = 0b_1111_0000hex_base = 0x_1234_abcd print(dec_base) # 1000000print(bin_base) # 240print(hex_base) # 305441741 Conclusion So far we’ve covered the of Python. While I’m a Python programmer, I didn’t know some of them till wrote this post. Especially, the is very new to me.Like me, I hope you gain some useful knowledges about from this post. underscore i18n/l10n underscore Next, I’ll cover more interesting things about Python. Thank you. _Update_ Added the new feature (PEP 515) was added in Python 3.6 is how hackers start their afternoons. We’re a part of the family. We are now and happy to opportunities. Hacker Noon @AMI accepting submissions discuss advertising &sponsorship To learn more, , , or simply, read our about page like/message us on Facebook tweet/DM @HackerNoon. If you enjoyed this story, we recommend reading our and . Until next time, don’t take the realities of the world for granted! latest tech stories trending tech stories