In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what are the new functions of Python3.9". In daily operation, I believe many people have doubts about the new functions of Python3.9. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what are the new functions of Python3.9?" Next, please follow the editor to study!
The New Direction of Python
There are two major changes in this update, although intuitively unaffected, but start to note: as a language, the development of Python will be slightly different. In short, it can be summarized as follows:
Python restrictions on parsers
Smaller versions and more frequent iterations
1. LL (1) and PEG
About 30 years ago, Guido Van Rosen wrote pgen, one of the first code written for Python, and is still used as a parser for Python today. The writing of Pgen is based on a syntax variant of LL (1), which indicates that if the parser wants to read the code in all directions, it only needs to advance the token. This basically shows that the development of Python is limited, because:
Advance tokens limit the expressiveness of syntax rules.
Because the current Python already contains non-LL (1) syntax, the parser circuitous scheme is complicated, which complicates the process.
Even with these solutions, the situation is limited. The rules can be changed but not broken.
Using LL (1)-specific left recursive syntax may cause the parse tree to parse in an infinite loop, resulting in a stack overflow.
These attributes of LL (1)-based parsers limit the value that Python can achieve, and Python 3.9 breaks these limitations, thanks to the shiny nova PEG parser, which PEP617 outlines. We won't feel it any time soon. The new parser will not change until Python 3.10 comes out, but after that, Python will break through the limitations of LL (1).
two。 Development cycle
Python's release plan will be reduced from 18 months to 12 months.
Before the release of version 3.9, Python was originally scheduled to be released every 18 months, but now it has entered a 12-month release schedule [PEP 602]. In the past, the new version only appeared once every 18 months, but now it is changed once a year. This also means that Python:
No longer launch a large number of new features at one time.
The change is more gradual, but due to the release of new features, the fix will be completed more quickly.
The release date is more regular, and the new Python will be available every October.
Therefore, in essence, this paper mainly focuses on the small incremental changes in the 12-month cycle, rather than the larger changes that occur every 18 months. At the same time, the development speed is expected to remain the same.
II. New functions
1. Type hint
Back in 2008, Python 3 introduced function annotations, the predecessor of type hints. Although it is not particularly powerful, it is an important beginning.
The real-time status of the Python type prompt is the accumulation of changes that have been added and modified multiple times and typed.
Since then, other functions have been added. Today, version 3.9 combines features with neat new syntax to get the latest developments in Python type hints.
Now we can easily specify the expected data type of the variable. If you write something meaningless (such as passing a string to an integer), the editor will alert you that an error has occurred. Although errors are not pointed out, it can be a great help when using complex code bases.
In Python, it is absolutely valid to concatenate two strings with "+". Therefore, the "add_int" function accepts two strings without raising any error.
No type prompt (left); Python3.9 with type prompt (right).
With the new type prompt, simply add: int to the parameter defined by the function, and the editor will immediately recognize the error.
Specify the expected input and output data types.
You can also use the-> type syntax to determine the value output type of the function.
Different types can be combined to create more complex annotations.
Don't confine yourself to simple predefined types!
two。 String method
Although not as cool as other changes, this method is used very frequently. There are two new ways to delete string prefixes and suffixes:
"foo bar" .removeprefix ("fo") [Out]:'o bar' "foo bar" .removesuffix ("ar") [Out]: 'foo b'
3. Merge dictionary
There are two new operators to merge dictionaries. The first is the merge operator |:
A = {1: 'axed, 2:' baked, 3:'c'} b = {4 print, 5:'e'} c = a | b print (c) [Out]: {1: 'axed, 2:' baked, 3: 'cased, 4VOV qualified, 5:' e'}
Then update the operator to merge in place:
A = {1: 'axed, 2:' baked, 3:'c'} b = {4 Python3.9 new functions, 5:'e'} a | = b print (a) [Out]: {1: 'axed, 2:' baked, 3: 'clocked, 4VOBZ: 5:' e'} this is the end of the study of "what are the new features of Python3.9". I hope to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.