Error debugging is accurate to lines, match case pattern matching... The official version of Python 3.10 is really friendly

Heart of machine 2021-10-28 18:48:47
error debugging accurate lines match

Python It is one of the most popular programming languages today , It has been widely used in various fields and applications , From learning the basic knowledge of computer science to performing complex and direct scientific computing tasks , Then to building games , Its shadow is everywhere .Python Even in more advanced fields such as data science and quantum computing .

2020 year 11 month ,Python 3.10  the second alpha edition Release , Expand in type annotation 、zip、 Bit count 、 Dictionary mapping has new improvements . This year, 4 month ,Python  3.10 beta edition Release , The biggest highlight is the introduction of switch-case sentence . after ,Python Several more have been released beta and rc(Release Candidate) edition .

10 month 4 Japan ,Python The official finally released Python 3.10 Official version . In the new version ,Python Added some unique and valuable features , At the same time, some old features have been deleted . Someone summed up 3.10 Three important features of version , Namely :
  • Better error tracking ;

  • match-case structure Pattern matching ;

  • new type Union Operator .

French scholars Thibault Clerice Express ,「 With Python 3.10 Release , Every programmer will love new 『 structure Pattern matching 』 function .」

about Python 3.10 New features , Assistant professor of statistics at the University of Wisconsin Madison 、 bestseller 《Python Machine Learning》 The author of Sebastian Raschka Express ,「 The most exciting of the new features is the improved error message prompt , Small mistakes like missing commas or spelling mistakes , Now it's easy to find .」

Besides , One netizen said ,Python 3.10 Adaptations have been provided Linux and macOS Systematic psycopg2 Binary package , but Windows The system has not been adapted .

Doctoral student in quantum computing, Keio University Sara A. Metwalli The author is right Python 3.10 The new features of , The following six new features and accessories are summarized .

Python 3.10 The latest features

characteristic 1: Better error tracking

As a daily use Python The code that writes the code , I'm sure I've stepped on the pit of grammatical errors . Although mature programmers can master Python skill , Grammatical errors can also be well fixed , But sometimes we want more accurate error messages , To help better locate errors , Save debugging time .

Python3.10 Two new features , Can better handle errors , That is, better error messages and precise line numbers for debugging . Take the following code as an example , The code contains dictionaries and functions , However, this code shows that the dictionary is not closed .

some_dict = {1: "jack", 2: "john", 3: "james" ,
a_results = a_useful_function()

Prior to Python In the version , The error message looks like this :

however , With Python 3.10 The arrival of the , New error messages and line numbering improvements , Can bring better error messages to coders , For example, the exact type of error and its exact line number can be tracked .

Python 3.10 New features on error tracking will help speed up debugging , And reduce beginner frustration .

characteristic 2: Introduction structure Pattern matching

If you have used C++ And other programming languages , Maybe you'll look forward to Python Yes switch sentence , So you don't have to go through a long if、 elif、 elif…. else Statement to complete the task .Python 3.10 A new feature of is the addition of structure Pattern matching , Or to put it another way , Added match case sentence , Its syntax is as follows :

match subject: 
 case <patt1>:
 <act1>
 case <patt2>:
 <act2>
 case <patt3>:
 <act3>
 case _:
 <action_default>

characteristic 3: new type Union Operator

Even though Python Is a dynamic type of programming language , But there are ways to make some parts of it static . for example , If you are writing a function , And properties (attributes) The type of is very important for the conversion inside the function . In previous releases , You can specify the type of property , for example :

def func(num: int) -> int: 
 return num + 5

But here's the problem , If you want to accept two types , You need to use Union keyword :

def func(num: Union[int, float]) -> Union[int, float]: return num + 5

stay Python 3.10 in , You can choose between two types , Use | Operator instead of Union To make more direct type decisions :

def func(num: int | float) -> int | float: 
 return num + 5

characteristic 4:Stricter Zipping

Python An interesting function in is zip() function , This is a Python Built in functions in , Allows you to combine and iterate elements from multiple sequences . In previous releases , You can use sequences of different lengths zip, But now a new parameter is introduced strict, Used to check passed to zip Whether all iteratable objects of the function have the same length .

characteristic 5: Automatic text encoding

Sometimes this happens to coding , The code can run on a machine , But on another machine, there will be an error . There are many reasons for this , Some are caused by text coding . stay Python In an earlier version , If the encoding type is not explicitly declared , The preferred local encoding may cause code errors on other computers . In the new version of Python3.10 in , If the user opens a text file without a specific encoding type , You can activate a warning to notify the user .

characteristic 6: Asynchronous iteration

Asynchronous programming is a powerful advanced programming paradigm , It since Python 3.5 It has been Python Part of . stay Python 3.10 in , There are two new asynchronous built-in functions aiter() and anext() Make the code more readable .

For many programmers ,Python It may be their preferred programming language .Python It has also topped many programming language rankings , Such as   IEEE 2021 Programming languages rank ,Python Ride a dust storm , It still firmly occupies the first place in the general list and several other sub lists . this Python 3.10 Release , Will be for Python This programming language brings a better programming experience .

Reference link :
https://towardsdatascience.com/6-new-awesome-features-in-python-3-10-a0598e87689f
版权声明
本文为[Heart of machine]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/10/20211013024959944q.html

  1. matlab改为python,偏最小二乘回归分析的一个程序
  2. 应该是python基础题希望能用基础方法解决
  3. 想找个会Python的做场外援助,上课没听明白
  4. Python程序,插入不了MySQL的date格式
  5. (初学者)关于Python操作Excel问题
  6. 求人来解答这两道Python题
  7. python中用三引号换行,举例说明
  8. python数码管该怎么用,十四段
  9. python进行中文文本聚类(切词以及Kmeans聚类)
  10. Python - 字符串作为文件
  11. Python - 转换二进制为ASCII码
  12. Python - 在段落中计算令牌
  13. Python - 重新格式化段落
  14. Python - 排序线
  15. Python - 字符串不变性
  16. Python - 文本摘要
  17. Python+微信小程序开发(六)双向绑定和前后端通信
  18. 基于Anaconda搭建Django环境
  19. Django基础篇(2)--视图
  20. 288页的python编程文档,从入门到实践,入门看这一篇就够了
  21. Python Web实战:Flask + Vue 开发一个漂亮的词云网站
  22. 让我深夜十二点催她睡觉,我用 Python 轻松搞定!
  23. 4.Python-常用语句
  24. 【Python】基于FastAPI的Restful规范实践
  25. 【Python】FastAPI脚手架:规范FastAPI后端接口项目开发
  26. 【Python】单元测试实践内部指南
  27. Django开发中使用Cache缓存提升10倍效率
  28. python如何重复执行程序命令而不是一次退出
  29. python 编写程序题使用for循环
  30. 一道简单的python作业题,就是不能运行
  31. 使用python回答,望有人来帮
  32. 用python插入日期格式到mysql数据库中,一直运行不了。
  33. 关于以下Python问题如何解决
  34. Use Python to help the financial sister solve the PDF splitting. The sister said it was great...
  35. Comment résoudre les problèmes Python suivants
  36. 如何使用python建立列表?新手入门
  37. python 3d画图库matplotlib,第一次用
  38. python 3d畫圖庫matplotlib,第一次用
  39. Python 3D painting Library matplotlib, utilisé pour la première fois
  40. Comment créer une liste en utilisant python? Débutant
  41. python定义列表 新手入门级别
  42. Liste de définition Python débutant
  43. 如何用Python实现,急!!xdm
  44. 如何用Python實現,急!!xdm
  45. Comment implémenter en python, urgent!! Xdm
  46. 新猿木子李:0基础学python培训教程 Python操作Redis之hash类型
  47. python导入模块变量后,打印的值固定不变了,大老们怎么破。
  48. Why is my rust slower than Python!
  49. 用Python给喜欢的女孩写一个办公小工具,她说棒极了!
  50. python中\t是空一个tab,那这个1.2后面怎么没空格?
  51. Il y a un onglet vide en python, alors pourquoi n'y a - t - il pas d'espace après ce 1.2?
  52. 关于python中pygame.display.set_mode()的一点小问题
  53. 猜我能否用Python编程抢到茅台?已经全部开源到GitHub了
  54. python数据分析numpy 补充短试题
  55. 2W + word long article, an article on literacy python, numpy and pandas, recommended collection!
  56. Python培训-自动化运维常用库
  57. On the magical usage and principle of weak reference in Python
  58. Formation python - bibliothèques d'exploitation et de maintenance automatisées
  59. Python培训-HTTP与HTTPS之间的区别
  60. Python有哪些高级特性?