In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "Python 3.9 new features example analysis", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "Python 3.9 new features for example analysis" it!
Dictionary union and iteratively updated dictionary union one of my favorite new features is fluent syntax. Python 3.9 dict class. If you have two dictionaries an and b, you can now use these operators to merge and update. We have the merge operator |: and the update operator | =, which updates the original dictionary: a = {1: 'axiom, 2:' baked, 3:'c'} b = {4: 'Dictionary, 5:' e'} a | = bprint (a) {1: 'ajar, 2:' baked, 3: 'clocked, 4:' encrypted, 5:'e'} if our dictionary shares a public key Then the key-value pair in the second dictionary will be used: a = {1: 'axiang, 2:' baked, 3: 'clocked, 6:' in both'} b = {4: 'dumped, 5:' eyed, 6: 'but different'} print (a | b) {1:' ajar, 2: 'baked, 3:' clocked, 6: 'but different', 4:' d' 5:'e'} another great performance of using Iterables for dictionary updates | = operator is the ability to update dictionaries with new key-value pairs using iterable objects such as lists or generators: a = {'aquired:' one', 'baked:' two'} b = ((I, itemized 2) for i in range (3)) a | = bprint (a) {'asides:' one', 'baked:' two'' 0: 0, 1: 1, 2: 4} if we try to use the standard union operator | A type error is prompted because it only allows union between dict types. String methods removeprefix () and removesuffix () str.removeprefix (substring:string) string methods: if str starts with it, it returns a new string with a modified prefix, otherwise it returns the original string. Str.removesuffix (substring:string) string method: if str ends with it, it returns a new string with a modified suffix, otherwise it returns the original string. The actions performed by these two functions will use string [len (prefix):] as the prefix and string [:-len (suffix)] as the suffix.
These are very simple operations, so they implement very simple functions, but given that they may be performed frequently, it is best to have a built-in function to do so. The type hints that Python is dynamically typed, and dynamically specifying the data type for the variable means that we do not need to specify the data type in the code. But sometimes it can cause confusion! For static allocation of data types, type hints are usually used. This was introduced in Python 3.5. From 3.5 onwards, we can specify the type, but this is troublesome. This update really changes that, and you can now use the built-in collection types (List and Dict) as generic types. Previously, you had to call the uppercase types List and Dict through input. Ef greet_all (names: list [str])-> None: for name in names: print ("Hello", name) now, there is no need to call List from typing.List. The new math module adds and improves a lot of auxiliary functions, starting with improvements to existing functions. Import math#Greatest common divisormath.gcd (80,64,152) # 8 previously gcd functions that calculate the greatest common factor can only be applied to two digits, forcing programmers to perform operations similar to math.gcd (80 math.gcd (64152)) when dealing with more numbers. Starting with Python 3.9, we can apply it to any numeric value. The first new addition to the math module is the math.lcm function: # Least common multiple math.lcm (4,8,5) # 40math.lcm calculates the least common multiple of its parameters. Like GCD, it allows a variable number of parameters. This part of the new parser is more of a change out of sight, but it is likely to be one of the most significant changes in the future development of Python. Python 3.9 uses a new PEG-based parser. Previously, Python used LL (1), and PEG is more flexible than LL (1) when building new features of the language. This flexibility will be reflected in Python 3.10 and later, according to official documentation. The ast module uses the new parser and produces the same AST as the old parser. Another change in the address of the IPv6 range Python 3.9 is that the range of IPv6 addresses can be specified. The IPv6 range is used to specify which part of the Internet is valid for the corresponding IP address. The range can be specified at the end of the IP address using the% sign-- for example: 3FFEVOVOVUR 0VUR 1RV 200F8FFRO FE75FFRIX50DF% 2MUE-so the IP address is in range 2, that is, the link local address. Therefore, if you need to use Python to handle IPv6 addresses, you can now do this: from ipaddress import IPv6Address addr = IPv6Address ('ff02::fa51%1') print (addr.scope_id) # "1"-interface-local IP address Note that when comparing using the basic Python operator, two addresses with different ranges are different. The new module area information zoneinfo module introduces the support of IANA time zone database into the standard library. It adds zoneinfo.ZoneInfo, a concrete datetime.tzinfo implementation supported by system time zone data. Other changes _ _ import _ _ () now add ImportError to replace ValueError, which usually occurs when the relative import exceeds its top-level package. "" .replace ("", sdirection n) now returns s instead of an empty string for all non-zero n. Now it is consistent with "". Replace (", s). By default, Python becomes faster. Each revision of Python has a performance improvement over previous versions. Python 3.9 makes two major improvements to improve performance without making any changes to existing code. The first improvement is more related to the use of vector calling protocols, making many common function calls by minimizing or eliminating temporary objects. Python 3.9 introduces several new built-in functions, including range, tuple, set, frozenset, list, dict-- using vectorcall can speed up execution. Python switched to the annual release cycle so far, Python has been developed and released at a pace of 18 months. PEP 602 proposed that the Python development team adopt an annual release cycle, and the proposal has been accepted. At this point, I believe you have a deeper understanding of "Python 3.9 New feature example Analysis". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.