Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Python 3.10 is updated again


May 28, 2021 Article blog



As the Python version continues to change, the official release of Python 3.10 is getting closer, and Python officially released a new alpha internal beta version of Python 3.10.0a6. E ven Uncle Turtle advertises on Twitter.

 Python 3.10 is updated again1

To help you learn better and faster about some of the new features of Python 3.10, the editor-in-chief will bring you seven new features of Python 3.10 today.
01.Python 3.10 alpha version installed
For the installation of the Python 3.10 alpha version, we'll show it here on the Windows platform. Y ou first go to Python's official website to download Python's installation package, the address of the official website is: https://www.Python.org/downloads/windows/. N ext is the download of the installation package, as shown in the following image:

 Python 3.10 is updated again2

There are two downloadable versions in the image above, namely zip compression package and exe executable file, for zip compression package, we download, directly unzip can be used, and exe file needs everyone to click to run, Python 3.10 environment installation, after installation, click Python .exe to get the results of the following image, indicating that we have successfully installed.

 Python 3.10 is updated again3

Introduction to the new features

For the Python 3.10 version, there are many new features that you need to understand, in order to better let everyone have a better understanding of Python 3.10 version, the following introduction, the small editor will try to add Python 3.10 version code and the old version (3.9 and previous versions) of the code comparison.
  • Type check improvements
  • Type alias changes
  • Frequency statistics
  • The Distutils library was discarded
  • The dictionary adds the mapping property
  • The function zip() adds new parameters
  • Template matching (similar to c-switch/case)

1). Type check improvements

 Python 3.10 is updated again4

In Python 3.10, the federation operator uses "|" T he line replaces the Union method in the older version, making the program cleaner, and not only that, Python 3.10 can also take advantage of "|" in some built-in functions T he union operator of the line to improve the performance of the program.

 Python 3.10 is updated again5

2). Changes to type aliases

 Python 3.10 is updated again6

In older versions, new names of types could be assigned directly from different types of assignments, while in Python 3.10, typeAlias specified the replacement of type names. T he advantage of this is that it gives program developers and Python editors a clearer idea of whether newname is a variable name or a type of alias, improving the reliability of program development.

3). The frequency in the binary representation is counted as a number of 1s

 Python 3.10 is updated again7

In Python 3.10, you can count the number of numbers "1" in binary by calling the bit_count function, and of course, in older versions, this can be done with very simple code.

4). Prepare to deprecation the Distutils built-in library

Since the functionality of the Distutils library has been replaced by this setuptools and package libraries, Distutils will be completely removed in the near future in the principle of simplicity.

 Python 3.10 is updated again8

5). The dictionary adds the mapping property

 Python 3.10 is updated again9

In Python 3.10, a new "mapping" property has been added to all three methods for the dictionary, items, keys, and values, and the program above can see that the original dictionary data is returned when the mapping property is called on all three methods.

6). The function zip() adds the strict argument

 Python 3.10 is updated again10

Python 3.10 adds a strict parameter to the zip function, which, as the name implies, is strictly adhered to the principle of matching parameter lengths, in which the length of the keys and values lists is not consistent. O lder versions of the zip function create dictionaries based on the shortest arguments. I n the new version of the zip function, when the strict parameter is set to True, the input parameters of the zip must be the same length, otherwise the error will be reported.

7). Template match

 Python 3.10 is updated again11

Python 3.10 introduces structured pattern matching through... C ase keywords are done to match dictionaries, classes, and other more complex structures. m atch... T he pattern matching of case has a lot in common with switch in C . I n the function shown above, the case function matches the tuple by matching the first example, if the third argument of the tuple is "male", and if the third argument of the tuple is "female", it matches to the second example, and if the previous case is not satisfied, the final default result is output.

summary:

The above is the small editor for everyone to bring about Python 3.10 of the new features of the sharing, especially the last one, let the rookie brother feel is not back to the C? / C language, it seems that Python is constantly absorbing nutrients from other languages to strengthen themselves, but still hope that Uncle Python can maintain their first heart!

Reprinted from: Rookie Python

That's all you'll find out about Python 3.10 and the updated version.