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 new features of python3.10

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

In this article, the editor introduces "what are the new features of python3.10" in detail, with detailed contents, clear steps and proper handling of details. I hope this article "what are the new features of python3.10" can help you solve your doubts.

A more friendly error tip

Many programming languages have their own error reporting mechanism, and as far as the editor's learning experience is concerned, the error prompt of python is relatively friendly. Editor to learn the first language is the C language, at that time using a generation of classic IDE--visual Category 6.0, it is compiled if there are errors in the code will be reported errors, editors feel that vc6.0 error reports are very detailed, we only need to modify the code according to the error tips to change the code, VC6.0 's advantage lies in this: his code tips are very detailed. However, because it is the C language, the code itself will be difficult to understand, which can not depend on its error prompt. It can only be said that the error prompt of the C language is like a sword that can be mastered by a master. For beginners of the C language, those who are not familiar with the C language grammar are not very friendly.

The second language that the editor learns is that the error report of java,java is actually very similar to that of python. Their error reports will print out the call stack. We can go to the call stack layer by layer to find the final error, and the error message of python is also more detailed. But languages that have a compilation process have one common drawback: they report all errors. The reason is that when they compile, they compile the whole code, instead of explaining it line by line like python, they will find all the errors in the whole code. If there are fewer code errors, such an error report will not hurt, but for beginners, seven or eight errors can be exposed by writing a helloworld, and the error prompt printed out with seven errors in java can have a large page. It is also full of all kinds of incomprehensible bags, which are directly baffled by beginners.

Then there is python, which is actually similar to java in the previous version of python, but it is different in two ways. First, he is relatively brief, giving only the reasons for the errors, such as simple prompts for grammatical errors. This is a disadvantage for other error reports. Second, because of the line-by-line interpretation of python, even if there are many errors in a piece of code, python will only report errors one by one, rather than reporting them all at once like compiled languages, which is an advantage for the readability of error reports.

But what we are going to introduce today is python3.10. The updated python error report solves the previous shortcomings, and now the python error report can also be more detailed. Let's take a look at the current python error report:

Str = "unclosed strFile" d:\ projects\ python\ learn\ Py310 exploration .py ", line 90 str =" unclosed str ^ SyntaxError: unterminated string literal (detected at line 90) arr = [1, 2, 2, 3 File "d:\ projects\ python\ learn\ Py310 exploration .py", line 91 arr = [1, 2, 2, 3 ^ SyntaxError:'[was never closed type annotation

Friends who like python have some dynamic variables that favor him. We don't need to declare the type of variable to refer to it. One second it is int, the next it becomes float. It all depends on my wishes. But this actually brings two problems. For the interpreter, to deal with these dynamic types, the interpreter needs to guess the type of the variable and convert it in time during the operation, which will reduce the efficiency of the interpreter. For programmers, for a function with a variable type, we do not need to look at the internal code of the function to know what type of parameter the function passes in and what type it returns. This cannot be done in older versions of python. In the old version of Python, we need to read the code of this function before we can guess the type of the incoming parameter and the return value (it looks like the dilemma encountered by the repetitive interpreter, but in fact, the problem that troubles the interpreter also bothers us). If the code amount of a function is small and easy to understand, or with comments, it may not have that great impact on us. But it's a disaster when the people who write the code don't write comments and the functions are complex and difficult to understand.

Type comments are included in the new version of python, which can significantly improve the readability of the code. The editor believes that this is also a key to improving the ease of learning of python.

Def f (x: int | float)-> float: return x * 3.142f (1) # passf (1.5) # passf ('str') # linter will show annotation error

Similar to the above, the parameter passed in may be int or float, although this part of the content is from the type annotation federation operator, but you can also see the content related to type annotation.

After reading this, the article "what are the new features of python3.10" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

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