Change language

Underline _ in Python files


The underscore (_) is special in Python. There are 5 uses for underscores in Python.

1. To store the value of the last expression in the interpreter.

The python interpreter stores the last value of the expression in a special variable named & # 8216; _ & # 8217 ;.

""" 12 + 10 22""" _ 22 

2. To ignore certain values. 

Underscore is also used to ignore certain values ​​in multiple languages ​​like elixir, erlang, python, etc. If you don’t need specific values ​​or don’t use values, just assign values ​​to the underscore.

For example

"" & gt ; _, _, a = (1, 2, 3)""" a 3 

3. Give special meaning to the names of variables and functions.

Variable names with one preceding underscore are used for private variables, functions, classes. Anything with this convention is ignored in the import * module. There are many other conventions you can check at:

4. Separate the digits of a number with a literal value.

In python, to avoid having to deal with very large numbers, you can use an underscore to make the numbers easy to read.


""" a = 7_200_000_000 # 7.2 billion easily readable""" a 7200000000 

Note that the last feature was added to Python in v3.6

< / p>

Underline _ in Python files _files: Questions

Underline _ in Python files Python functions: Questions


Best laptop for Fortnite


Best laptop for Excel


Best laptop for Solidworks


Best laptop for Roblox


Best computer for crypto mining


Best laptop for Sims 4


Best laptop for Zoom


Best laptop for Minecraft


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers



Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method