Data Types数据类型¶
The modules described in this chapter provide a variety of specialized data types such as dates and times, fixed-type arrays, heap queues, double-ended queues, and enumerations.本章中描述的模块提供了各种专用数据类型,如日期和时间、固定类型数组、堆队列、双端队列和枚举。
Python also provides some built-in data types, in particular, Python还提供了一些内置的数据类型,特别是dict
, list
, set
and frozenset
, and tuple
. dict
、list
、set
和frozenset
以及tuple
。The str
class is used to hold Unicode strings, and the bytes
and bytearray
classes are used to hold binary data.str
类用于保存Unicode字符串,bytes
和bytearray
类用于保存二进制数据。
The following modules are documented in this chapter:本章记录了以下模块:
datetime
—Basic date and time types基本日期和时间类型zoneinfo
—IANA time zone supportIANA时区支持calendar
—General calendar-related functions常规日历相关功能collections
—Container datatypes容器数据类型collections.abc
—Abstract Base Classes for Containers容器的抽象基类heapq
—Heap queue algorithm堆队列算法bisect
—Array bisection algorithm阵列对分算法array
—Efficient arrays of numeric values有效的数值数组weakref
—Weak references弱引用types
—Dynamic type creation and names for built-in types动态类型创建和内置类型的名称copy
—Shallow and deep copy operations浅拷贝和深拷贝操作pprint
—Data pretty printer数据漂亮打印机reprlib
—Alternate备用repr()
implementationrepr()
实现enum
—Support for enumerations支持枚举Module Contents模块内容Creating an Enum创建枚举Programmatic access to enumeration members and their attributes对枚举成员及其属性的编程访问Duplicating enum members and values复制枚举成员和值Ensuring unique enumeration values确保枚举值唯一Using automatic values使用自动值Iteration迭代Comparisons比较Allowed members and attributes of enumerations允许的枚举成员和属性Restricted Enum subclassing受限枚举子类化Pickling酸洗Functional API功能APIDerived Enumerations派生枚举When to use何时使用__new__()
vs.__init__()
__new__()
与__init__()
Interesting examples有趣的例子How are Enums different?枚举有何不同?
graphlib
—Functionality to operate with graph-like structures使用类似图形的结构进行操作的功能