In Python in some cases we use Single Underscore(_) and some cases we use Double Underscores (__).
In Python has following cases, where we use underscore.
Now some examples on every cases.
The Python Interpreter stores the last expression value in the '_'.
>>> 20 20 >>> _ 20 >>> _ + 3 23
Underscore is also used for ignoring the values.
x, _, y = (1, 2, 3)
Here x = 1, y = 3 and ignore the value 2.
Python does not support private, so we cannot force something’s private ones but we can call it directly from other modules.
Using this conversion easily can avoid conflicting of Python keywords and built-ins.
This is mangle, it is used to avoid conflicts of attributes name between names.
If you write a method name “__display” in a class, the name will be mangled in “_ClassName__display” form.
In some cases we use this conversion. Just like _init_.
dec_base = 1_000_000 print(dec_base) # 1000000
This is just a convention not any syntactic functions here underscore just bind the i18n/l10n to underscore variable has been from C convention.