Electron microscopy
 
_ (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:
        Add 60 to argument a, and return the result
Output:
        True
        6

===========================================

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:
        Add 60 to argument a, and return the result
Output:
        8

===========================================

"_" ignore a value and "*_" ignores multiple values: code:
        Add 60 to argument a, and return the result
Output:
        1 7
        1 7

===========================================

Represents a variable in looping: code:
        Add 60 to argument a, and return the result
Output:
        0
        1
        2
        3
        4

        USA
        Canada
        Italy
        Germany

        6
        7
        8
        9
        10
        11

===========================================

Separate digits of numbers or separate the binary, octal or hex parts of numbers: code:
        Add 60 to argument a, and return the result
Output:
        2000000
        14        
        60
        18347

===========================================

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:
        Add 60 to argument a, and return the result
Output:
        9

===========================================

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:
        Add 60 to argument a, and return the result
Output ("_Example__z" was changed due to mangling):
        Add 60 to argument a, and return the result

===========================================

Double pre and post underscores, which is so-called magic methods or dunder methods, e.g. __init__, etc.



 

=================================================================================