Most people do not know the new features of Python 3.8

Python 3.8 is the latest version of the Python language, which is suitable for a variety of tasks to write scripts, automation, and machine learning, and Web development.

Python 3.8 has now entered the official beta stage, this version brings many grammatical changes, memory sharing, more efficient serialization and de-serialization, improved dictionary and more new features.

Python 3.8 also introduces a number of performance improvements. Overall, we are about to have a faster, more accurate, more consistent and more modern Python.

Here is the Python 3.8's new features and the most important changes, I summed up, some developers with common characteristics obtained.

1, the operator walrus

The most obvious change is the assignment expression Python 3.8, the " : = " operator. Assignment expression can speak a value to a variable, even if the variable does not exist can be. It can be used in expressions, without having to appear as a separate statement.

a = 6
if b:=a+1>6:
print(b)

When the assignment operation can be carried out simultaneously, and similar to the assignment in Go.

Run the code sequence, first a + 1 is calculated to obtain a value of 7, then 7 assigned to B, this corresponds to the code where the following:

a = 6
b = a+1
if b > 6:
print(b)

2, f string debugging support

f string format can more easily calculate the output text and variable values ​​or within the same expression, and more efficient.

x = 3 
print(f'{x+1}')

Output: 4

No expression at the end of the string f = f expression itself may output value, followed by the calculated value

x = 3
print (f'{x+1=}')

Output: x + 1 = 4

3, can reverse dictionary

Python3.6 rewrite the dictionary, which uses a new implementation project PyPy contribution. In addition to faster and more compact, the dictionary will now inherit the order of elements - elements will be arranged in the order added, just like a list. Python 3.8 also allows reversed in the dictionary ().

 

More exciting, please pay attention to my "Today's headlines No": Java cloud notes
anywhere, so you have the latest and most convenient Pocket Cloud Services

Published 165 original articles · won praise 270 · views 80000 +

Guess you like

Origin blog.csdn.net/weixin_44259720/article/details/104772396