13518219792

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

创新互联Python教程:Python 3.1 有什么新变化

python 3.1 有什么新变化

作者

成都创新互联公司是一家专注于做网站、成都网站制作与策划设计,遂川网站建设哪家好?成都创新互联公司做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:遂川等地区。遂川做网站价格咨询:028-86922220

Raymond Hettinger(译者:wh2099 at outlook dot com)

本文介绍了 Python 3.1 相比 3.0 的新特性。 Python 3.1 发布于 2009 年 6 月 27 日。

PEP 372: 有序字典

常规的 Python 字典会以任意顺序迭代键/值对。 多年以来,有好几位作者编写了可以记住键的初始插入顺序的替代实现。 基于这些实现的经验,现在引入了新的 collections.OrderedDict 类。

The OrderedDict API is substantially the same as regular dictionaries but will iterate over keys and values in a guaranteed order depending on when a key was first inserted. If a new entry overwrites an existing entry, the original insertion position is left unchanged. Deleting an entry and reinserting it will move it to the end.

The standard library now supports use of ordered dictionaries in several modules. The configparser module uses them by default. This lets configuration files be read, modified, and then written back in their original order. The _asdict() method for collections.namedtuple() now returns an ordered dictionary with the values appearing in the same order as the underlying tuple indices. The json module is being built-out with an object_pairs_hook to allow OrderedDicts to be built by the decoder. Support was also added for third-party tools like PyYAML.

参见

PEP 372 - 有序字典

PEP 由 Armin Ronacher 和 Raymond Hettinger 撰写,由 Raymond Hettinger 实现。

PEP 378: 千位分隔符的格式说明符

The built-in format() function and the str.format() method use a mini-language that now includes a simple, non-locale aware way to format a number with a thousands separator. That provides a way to humanize a program’s output, improving its professional appearance and readability:

 
 
 
 
  1. >>> format(1234567, ',d')
  2. '1,234,567'
  3. >>> format(1234567.89, ',.2f')
  4. '1,234,567.89'
  5. >>> format(12345.6 + 8901234.12j, ',f')
  6. '12,345.600000+8,901,234.120000j'
  7. >>> format(Decimal('1234567.89'), ',f')
  8. '1,234,567.89'

支持的类型有 int, float, complex 和 decimal.Decimal。

Discussions are underway about how to specify alternative separators like dots, spaces, apostrophes, or underscores. Locale-aware applications should use the existing n format specifier which already has some support for thousands separators.

参见

PEP 378 - 千位分隔符的格式说明符

PEP 由 Raymond Hettinger 撰写,并由 Eric Smith 和 Mark Dickinson 实现

其他语言特性修改

对Python 语言核心进行的小改动:

新增,改进和弃用的模块

(由 Antoine Pitrou 和 Jesse Noller 提议,由 Jack Diederich 实现; bpo-5228。)

性能优化

Major performance enhancements have been added:

IDLE

构建和 C API 的改变

针对 Python 构建过程和 C API 的改变包括:

移植到 Python 3.1

This section lists previously described changes and other bugfixes that may require changes to your code:


本文题目:创新互联Python教程:Python 3.1 有什么新变化
分享地址:http://cdbrznjsb.com/article/djhdppo.html

其他资讯

让你的专属顾问为你服务