
In this article, we will learn the new features in Python 3.10, compared to 3.9. Let’s see the features −
Parenthesized context managers
现在支持使用括号来跨多行继续使用上下文管理器。这样可以以与之前的导入语句相似的方式,将长的上下文管理器集合格式化为多行。
User-Defined Type Guards
TypeGuard has been added to the typing module to annotate type guard functions and improve information provided to static type checkers during type narrowing.
Enhanced error messages
如果您在运行Python程序时遇到错误,错误消息现在将更准确,并提供确切的错误信息
立即学习“Python免费学习笔记(深入)”;
SyntaxError
的中文翻译为:SyntaxError
在解析包含未闭合括号或方括号的代码时,解释器现在会包括未闭合括号或方括号的位置,而不是显示SyntaxError: unexpected EOF while parsing或指向错误的位置
SyntaxError exceptions raised by the interpreter will now highlight the full error range of the expression that constitutes the syntax error itself, instead of just where the problem is detected.
IndentationErrors
的翻译为:缩进错误
许多IndentationError异常现在提供了更多关于期望缩进的块类型的上下文信息
精确的行号用于调试
More precise and reliable line numbers for debugging, profiling and coverage tools. Tracing events, with the correct line number, are generated for all lines of code executed and only for lines of code that are executed.
BJXShop网上购物系统是一个高效、稳定、安全的电子商店销售平台,经过近三年市场的考验,在中国网购系统中属领先水平;完善的订单管理、销售统计系统;网站模版可DIY、亦可导入导出;会员、商品种类和价格均实现无限等级;管理员权限可细分;整合了多种在线支付接口;强有力搜索引擎支持... 程序更新:此版本是伴江行官方商业版程序,已经终止销售,现于免费给大家使用。比其以前的免费版功能增加了:1,整合了论坛
Structural Pattern Matching
已经通过匹配语句和带有关联操作的模式的case语句添加了结构模式匹配。模式包括序列、映射、原始数据类型以及类实例。模式匹配使程序能够从复杂的数据类型中提取信息,根据数据的结构进行分支,并根据不同形式的数据应用特定的操作。
增强模块
以下模块增加了新功能、新方法等。
array − The index() method of array.array now has optional start and stop parameters.
base64 − Added base64.b32hexencode() and base64.b32hexdecode() to support the Base32 Encoding with Extended Hex Alphabet.
bisect − Added the possibility of providing a key function to the APIs in the bisect module.
contextlib − 添加了一个contextlib.aclosing()上下文管理器,用于安全关闭异步生成器和表示异步释放资源的对象。
distutils − The distutils package is deprecated, to be removed in Python 3.12.
encodings − The encodings.normalize_encoding() now ignores non-ASCII characters.










