Python 3.5 有什麼新功能¶
- 編輯者:
Elvis Pranskevichus <elvis@magic.io>, Yury Selivanov <yury@magic.io>
本文介紹了 Python 3.5 與 3.4 相比多了哪些新功能。Python 3.1 已於 2015 年 9 月 13 日發布。完整詳情請見 changelog。
也參考
PEP 478 - Python 3.5 發佈時程
發布重點摘要¶
新增語法特性:
PEP 492,使用 async 和 await 語法的協程
PEP 465, a new matrix multiplication operator:
a @ b.PEP 448, additional unpacking generalizations.
新的函式庫模組:
新的內建功能
bytes % args,bytearray % args: PEP 461 -- Adding%formatting to bytes and bytearray.New
bytes.hex(),bytearray.hex()andmemoryview.hex()methods. (Contributed by Arnon Yaari in bpo-9951.)memoryviewnow supports tuple indexing (including multi-dimensional). (Contributed by Antoine Pitrou in bpo-23632.)Generators have a new
gi_yieldfromattribute, which returns the object being iterated byyield fromexpressions. (Contributed by Benno Leslie and Yury Selivanov in bpo-24450.)A new
RecursionErrorexception is now raised when maximum recursion depth is reached. (Contributed by Georg Brandl in bpo-19235.)
CPython 實作改進:
When the
LC_TYPElocale is the POSIX locale (Clocale),sys.stdinandsys.stdoutnow use thesurrogateescapeerror handler, instead of thestricterror handler. (Contributed by Victor Stinner in bpo-19977.).pyofiles are no longer used and have been replaced by a more flexible scheme that includes the optimization level explicitly in.pycname. (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.)
標準函式庫中的顯著改進
collections.OrderedDictis now implemented in C, which makes it 4 to 100 times faster.The
sslmodule gained support for Memory BIO, which decouples SSL protocol handling from network IO.The new
os.scandir()function provides a better and significantly faster way of directory traversal.functools.lru_cache()has been mostly reimplemented in C, yielding much better performance.The new
subprocess.run()function provides a streamlined way to run subprocesses.The
tracebackmodule has been significantly