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: https://hackernoon.com/understanding-the-underscore-of-python-309d1a029edc

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.

Example

""" 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

Shop

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

$499

Best laptop for Minecraft

$590

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () 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