Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between Python3.10 and Python3.9 versions

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "what are the differences between Python3.10 and Python3.9 versions". The explanation in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the differences between Python3.10 and Python3.9 versions"?

Introduction:

Over the past few decades, Python has created a name for itself in the field of programming or scripting languages. The main reason why python is so popular is its extreme user-friendliness. Python is also used to deal with complex programs or coding challenges.

Emerging fields such as machine learning (ML), artificial intelligence (AI) and data science also meet the high demand for learning the language. Compared with traditional languages such as Java, C #, and other languages, Python is a powerful programming language that has quickly become a favorite among developers, data scientists, and AI/ML enthusiasts.

As a programming language, Python has many use cases that attract learners and experts in the IT industry. At a basic level, Python can be used as a programming language to practice data structures and algorithms or to develop simple projects or games.

The versatility of Python as a language makes it easy for its users to extend their projects and create websites, software, or predictive models. Automation is taking over most of the IT industry, and Python is leading the way as the preferred language for automating data analysis or data science tasks.

In addition, Python has a large number of libraries and a strong community of programmers who continue to add more value to Python as a language.

Learn about Python and its use cases:

One of the many reasons beginners are attracted to Python is its user-friendliness. Python abandons the intimidating semicolon and uses a simple indentation structure as its syntax. Python also found a use case as an extension of an application that requires a programmable interface.

Some of the other benefits of Python include its most coveted feature, its library. The Python library is a huge resource that can be used for many key coding tasks, such as:

Code based on regular expressions

string manipulation

Internet protocols, such as HTTP, FTP, SMTP, XML-RPC, POP, IMAP

Unified code

Differences between file systems and compute files

CGI programming

Mathematical modeling

Database query

Data analysis

Data visualization

Automation code

All of these functions can be performed on many Unix, Linux, macOS, and Windows systems.

Analyze the difference of Python 3.9V Python 3.10

Over the years, Python has undergone a number of upgrades and many features have been added to the new version. Here, let's take a look at the two latest versions added by Python. Exploring updated features can help you use it smoothly, and of course, you can find smarter ways to work with the update library.

All the code attached below is for educational purposes only and is taken from the original Python document released with new versions such as Python 3.9 and Python 3.10

Python 3.9:IANA time zone database

A new module called zoneinfo was created in Python 3.9. Through this module, you can access the IANA or Internet number assignment Authority time zone database. By default, this module uses the system's local time zone data.

Code:

Print (datetime (2021, 7, 2, 12, 0). Astimezone () print (datetime (2021, 7, 2, 12, 0). Astimezone (). Strftime ("% Y-%m-%d% H:%M:%S% Z") print (datetime (2021, 7, 2, 12, 0) .astimezone (timezone.utc))

Output:

2020-07-2 12:00:00-05 EST2020 002020-07-2 12:00:00 function for merging and updating dictionaries

Python 3.9 has added another cool feature that has attracted a lot of attention. Python 3.9 can now use operations to match and or update dictionaries. The new operators ie (|) and (| =) have been added to the Python 3.9 built-in dict class.

You can access these operators to merge or update dictionaries using code similar to the following markup.

Code:

> a = {'vested: 1,' art': 2, 'py': 3} > b = {' vested: 'dashed,' topic': 'python3.9'}

Merge Code:

> a | b {'art': 2,' py': 3, 'py': py': 3,' topic':'python3.9'}, 'topic':'python3.9'} > b | a {' vested: 1

Update the code:

> a | = b > > a {'art': 2,' py': 3 delete prefixes and suffixes

String handling problems can be solved more easily by using the new features added in Python 3.9. The code marked below is used to remove prefixes and suffixes from the sample string. The new method used in the following sample code is:

Removeprefix ()-this method, aptly named according to its function, removes prefixes that exist in a given sample string. Removesuffix ()-this method removes the existing suffix from the sample string passed to it.

Due to programmers' negative comments on the nature of their defects, these new methods are created to replace the old strip () method. Marked below is a sample code that can help you understand the implementation of these two new methods.

Code:

Print ("the sea is playing outside" .removeprefix ("sea hug")

Output:

Play outside uses type hints for built-in generic types in Python 3.9

Python version 3.9 enables support for the common syntax of all standard collections, which are currently available in the input module. A generic type is usually defined as a container, such as a list. It is a type that can be easily parameterized. In general, generic types have one or more types of parameters, while parameterized generics are specific instances of generic data types with container elements, for example, list or dictionary built-in collection types are supported types, rather than specifically supported types using Typing.Dict or typing.List

Code:

Def print_value (input: str): # specifies that the value passed will be of type string

We will be able to find out whether the following input is a string by using the following ways

Python 3.10:

Match using structural patterns

A new feature called structural pattern matching has been introduced in the new Python 3.10. This matching process runs with the same matching case logic, but it is also compared with the comparison object to track a given pattern.

The code for Python 3.9:

Http_code = "419" if http_code = = "200": print ("OK") elif http_code = = "404": print ("Not Found Here") elif http_code = = "419": print ("Value Found") else: print ("Code not found")

The code for Python 3.10:

Http_code = "419" match http_code: case "200": print ("Hi") case "404": print ("Not Found") case "419": print ("You Found Me") case _: # Default Case print ("Code not found") improved syntax error message

A large number of programmers face difficulties in mismatching or debugging code. Python 3.10 adds a very user-friendly feature called association suggestion, which is marked with syntax error messages. This helps you quickly find fixes for the code in which there are errors or errors.

Code:

Named_car = 77print (new_car)

Output:

NameError: name 'new_car' is not defined. Did you mean: named_car? Better type tips

Upgrading from Python 3.9, we can use OR symbols instead of the union keyword to assign multiple input types of parameters. It is easier to define multiple input types for the same variable

The code for Python 3.9:

Def add (a: Union [int, float], b: Union [int, float]):

The code for Python 3.10:

Def add (a: int | float, b: int | float): improved context manager

The context manager helps with resources such as files. You can now use multiple contexts in a single block. This will greatly enhance your code because you no longer need multiple blocks or statements.

Previous syntax:

With open ('output.log',' rw') as fout: fout.write ('hello')

The latest grammar:

With (open ('output.log',') as fout, open ('input.csv') as fin): fout.write (fin.read ()) Thank you for your reading. This is the content of "what are the differences between Python3.10 and Python3.9 versions". After studying this article, I believe you have a deeper understanding of the differences between Python3.10 and Python3.9 versions. The specific use situation still needs to be verified by 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report