In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the new features of Python3.9". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the new features of Python3.9"?
1. Dictionary joint operator
This is one of my favorite functions, and the grammar is very beautiful.
In Python3.9, if you have two dictionaries, you can now merge and update with these operators.
Merge operator "|":
There is also the update operator | =, which updates the original dictionary:
A = {1: 'axed, 2:' baked, 3:'c'} b = {4: 'dumped, 5:' e'} a | = b print (a) {1: 'axed, 2:' baked, 3: 'clocked, 4:' dashed, 5:'e'}
If our dictionary shares a key, then the value in the second dictionary will be used:
A = {1: 'axed, 2:' baked, 3: 'caged, 6:' in both'} b = {4: 'dashed, 5:' eyed, 6: 'but different'} print (a | b) {1:' axed, 2: 'baked, 3:' cased, 6: 'but different', 4:' dashed, 5:'e'}
Updating dictionaries with iterable objects
| another cool feature of the = operator is the ability to update dictionaries with new key-value pairs using iterable objects such as lists or generators:
A = {'averse:' one', 'baked:' two'} b = ((I, iPrecipitated 2) for i in range (3)) a | = b print (a) {'axed:' one', 'baked:' two', 0: 0,1: 1,2: 4}
Of course, if you use | to do this, you will get TypeError, because it can only be used for unions between dict types.
two。 String method
Removeprefix () and removesuffix ()
Str.removeprefix (substring: string) is a method that takes a substring parameter, which, as the name implies, removes the substring prefix corresponding to the string and returns the original string if there is no corresponding prefix.
Str.removesuffix (substring: string) is a method that receives a substring parameter that removes the corresponding substring suffix of the string and returns the original string if there is no corresponding suffix.
Of course, you can execute two functions by using the string [len (prefix):] prefix and the string [:-len (suffix)] suffix.
These are very simple operations, so they are also very simple functions, and considering that you may perform these operations often, these two built-in functions provided by Python3.9 should make you feel good.
3. New mathematical function
The mathematical module of Python 3.9 has been optimized and many new functions have been added.
For example, in the past, gcd's function of calculating the maximum common factor could only be applied to 2 digits, which is very painful, so we have to use math.gcd (80, math.gcd (64,152)) to deal with cases with more than 2 digits.
Gcd now allows you to calculate any number of numbers.
Import math # Greatest common divisor math.gcd (80,64,152) # 8
The first new feature in the Math module is:
# least common multiple math.lcm (4,8,5) # 40
Used to calculate the least common multiple: math.lcm, which, like gcd, allows a variable number of parameters.
4. New parser-PEG
This change may be invisible and untouchable, but it could change the future of Python.
Python used to use the LL (1) parser, and starting with Python 3.9, it will use the PEG parser, and officials believe this change will make it easier for them to build new features.
Thank you for your reading, these are the contents of "what are the new features of Python3.9". After the study of this article, I believe you have a deeper understanding of what the new features of Python3.9 have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.