_ (underscore) in Python - Integrated Circuits - - An Online Book - |
||||||||
Integrated Circuits http://www.globalsino.com/ICs/ | ||||||||
================================================================================= | ||||||||
Single and double underscores have a meaning in Python variable and method names. Some are used only by convention and intended as a hint to the programmer, while some are enforced by the Python interpreter. =========================================== The single underscore (_) is bound to the last expression evaluated (e.g. "lambda" below): code: =========================================== Single leading underscore: =========================================== Variable names in Python must start with a letter or an underscore
“_”. The single underscore prefix has a meaning by convention only when it is used to variable and method names: code: =========================================== "_" ignore a value and "*_" ignores multiple values: code: =========================================== Represents a variable in looping: code: USA 6 =========================================== Separate digits of numbers or separate the binary, octal or hex parts of numbers: code: =========================================== You can add an underscore at the end of the name which you want to use if you want to use Python Keywords as a variable: code: =========================================== A double underscore prefix causes the Python interpreter to rewrite the attribute name in order to avoid naming conflicts in subclasses. This is also called name mangling. code: =========================================== Double pre and post underscores, which is so-called magic methods or dunder methods, e.g. __init__, etc.
|
||||||||
================================================================================= | ||||||||
|
||||||||