In this article, we will learn the new features in Python 3.10, compared to 3.9. Let’s see the features −
现在支持使用括号来跨多行继续使用上下文管理器。这样可以以与之前的导入语句相似的方式,将长的上下文管理器集合格式化为多行。
TypeGuard has been added to the typing module to annotate type guard functions and improve information provided to static type checkers during type narrowing.
如果您在运行Python程序时遇到错误,错误消息现在将更准确,并提供确切的错误信息
在解析包含未闭合括号或方括号的代码时,解释器现在会包括未闭合括号或方括号的位置,而不是显示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.
许多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.
已经通过匹配语句和带有关联操作的模式的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.
以上是Python 3.10版本中新增了哪些新功能?的详细内容。更多信息请关注PHP中文网其他相关文章!