Python 3.5 的新功能

编辑器 :

Elvis Pranskevichus < elvis @ magic . io >, Yury Selivanov < yury @ magic . io >

This article explains the new features in Python 3.5, compared to 3.4. Python 3.5 was released on September 13, 2015.  See the changelog for a full list of changes.

另请参阅

PEP 478 - Python 3.5 Release Schedule

摘要 – 发行亮点

新句法特征:

  • PEP 492 , coroutines with async and await syntax.

  • PEP 465 , a new matrix multiplication operator: a @ b .

  • PEP 448 , additional unpacking generalizations.

新的库模块:

新的内置特征:

CPython 实现改进:

  • LC_TYPE locale is the POSIX locale ( C locale), sys.stdin and sys.stdout now use the surrogateescape error handler, instead of the strict error handler. (Contributed by Victor Stinner in bpo-19977 )。

  • .pyo files are no longer used and have been replaced by a more flexible scheme that includes the optimization level explicitly in .pyc name. (See PEP 488 overview )。

  • Builtin and extension modules are now initialized in a multi-phase process, which is similar to how Python modules are loaded. (See PEP 489 overview )。

Significant improvements in the standard library:

Security improvements:

  • SSLv3 is now disabled throughout the standard library. It can still be enabled by instantiating a ssl.SSLContext manually. (See bpo-22638 for more details; this change was backported to CPython 3.4 and 2.7.)

  • HTTP cookie parsing is now stricter, in order to protect against potential injection attacks. (Contributed by Antoine Pitrou in bpo-22796 )。

Windows improvements:

  • A new installer for Windows has replaced the old MSI. See 在 Windows 使用 Python 了解更多信息。

  • Windows builds now use Microsoft Visual C++ 14.0, and extension modules should use the same.

Please read on for a comprehensive list of user-facing changes, including many other smaller improvements, CPython optimizations, deprecations, and potential porting issues.

新特征

PEP 492 - Coroutines with async and await syntax

PEP 492 greatly improves support for asynchronous programming in Python by adding 可期待对象 , coroutine functions , asynchronous iteration ,和 异步上下文管理器 .

Coroutine functions are declared using the new async def syntax:

>>> async def coro():
...     return 'spam'