This document is for an old version of Python that is no longer supported. You should upgrade and read the Python 当前稳定版本的文档.

# 8. 数据类型

The modules described in this chapter provide a variety of specialized data types such as dates and times, fixed-type arrays, heap queues, synchronized queues, and sets.

Python also provides some built-in data types, in particular, `dict`, `list`, `set` (which along with `frozenset`, replaces the deprecated `sets` module), and `tuple`. The `str` class can be used to handle binary data and 8-bit text, and the `unicode` class to handle Unicode text.

本章包含以下模块的文档：

- 8.1. `datetime` — 基本的日期和时间类型
  - 8.1.1. 有效的类型
  - 8.1.2. `timedelta` 类对象
  - 8.1.3. `date` 对象
  - 8.1.4. `datetime` 对象
  - 8.1.5. `time` 对象
  - 8.1.6. `tzinfo` 对象
  - 8.1.7. `strftime()` 和 `strptime()` 的行为
- 8.2. `calendar` — 日历相关函数
- 8.3. `collections` — High-performance container datatypes
  - 8.3.1. `Counter` 对象
  - 8.3.2. `deque` 对象
    - 8.3.2.1. `deque` 用法
  - 8.3.3. `defaultdict` 对象
    - 8.3.3.1. `defaultdict` 例子
  - 8.3.4. `namedtuple()` 命名元组的工厂函数
  - 8.3.5. `OrderedDict` 对象
    - 8.3.5.1. `OrderedDict` 例子和用法
  - 8.3.6. Collections Abstract Base Classes
- 8.4. `heapq` — 堆队列算法
  - 8.4.1. 基本示例
  - 8.4.2. 优先队列实现说明
  - 8.4.3. 理论
- 8.5. `bisect` — 数组二分查找算法
  - 8.5.1. 搜索有序列表
  - 8.5.2. 其他示例
- 8.6. `array` — 高效的数值数组
- 8.7. `sets` — Unordered collections of unique elements
  - 8.7.1. Set Objects
  - 8.7.2. Example
  - 8.7.3. Protocol for automatic conversion to immutable
  - 8.7.4. Comparison to the built-in `set` types
- 8.8. `sched` — 事件调度器
  - 8.8.1. 调度器对象
- 8.9. `mutex` — Mutual exclusion support
  - 8.9.1. Mutex Objects
- 8.10. `Queue` — A synchronized queue class
  - 8.10.1. Queue对象
- 8.11. `weakref` — 弱引用
  - 8.11.1. 弱引用对象
  - 8.11.2. 示例
- 8.12. `UserDict` — Class wrapper for dictionary objects
- 8.13. `UserList` — Class wrapper for list objects
- 8.14. `UserString` — Class wrapper for string objects
- 8.15. `types` — Names for built-in types
- 8.16. `new` — Creation of runtime internal objects
- 8.17. `copy` — 浅层 (shallow) 和深层 (deep) 复制操作
- 8.18. `pprint` — 数据美化输出
  - 8.18.1. PrettyPrinter 对象
  - 8.18.2. pprint Example
- 8.19. `repr` — Alternate `repr()` implementation
  - 8.19.1. Repr Objects
  - 8.19.2. Subclassing Repr Objects