uTools-Manuals/docs/python/datatypes.html
2019-04-08 23:22:26 +08:00

1 line
16 KiB
HTML

<div class="body" role="main"><div class="section" id="data-types"><h1><span class="yiyi-st" id="yiyi-9">8.</span><span class="yiyi-st" id="yiyi-10">数据类型</span></h1><p><span class="yiyi-st" id="yiyi-11">在这一章中描述的模块提供各种专门的数据类型,例如日期和时间、 固定类型数组、 堆栈队列、 同步队列和集合。</span></p><p><span class="yiyi-st" id="yiyi-12">Python 还提供了一些内置的数据类型,特别是 <a class="reference internal" href="stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal"><span class="pre">字典</span></code></a>, <a class="reference internal" href="stdtypes.html#list" title="list"><code class="xref py py-class docutils literal"><span class="pre">列表</span></code></a>, <a class="reference internal" href="stdtypes.html#set" title="set"><code class="xref py py-class docutils literal"><span class="pre">集合</span></code></a><a class="reference internal" href="stdtypes.html#frozenset" title="frozenset"><code class="xref py py-class docutils literal"><span class="pre">封闭集合</span></code></a>, 还有 <a class="reference internal" href="stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal"><span class="pre">元组</span></code></a></span><span class="yiyi-st" id="yiyi-13"><a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal"><span class="pre">str</span></code></a> 类用来保存 Unicode 字符串, <a class="reference internal" href="functions.html#bytes" title="bytes"><code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></a> 类用来保存二进制数据。</span></p><p><span class="yiyi-st" id="yiyi-14">在这一章介绍了下列模块︰</span></p><div class="toctree-wrapper compound"><ul><li class="toctree-l1"><span class="yiyi-st" id="yiyi-23"><a class="reference internal" href="datetime.html">8.1. <code class="docutils literal"><span class="pre">datetime</span></code> — 基本日期和时间类型</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-15"><a class="reference internal" href="datetime.html#available-types">8.1.1. 可用类型</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-16"><a class="reference internal" href="datetime.html#timedelta-objects">8.1.2. <code class="docutils literal"><span class="pre">timedelta</span></code> 对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-17"><a class="reference internal" href="datetime.html#date-objects">8.1.3. <code class="docutils literal"><span class="pre">date</span></code> 对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-18"><a class="reference internal" href="datetime.html#datetime-objects">8.1.4. <code class="docutils literal"><span class="pre">datetime</span></code> 对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-19"><a class="reference internal" href="datetime.html#time-objects">8.1.5. <code class="docutils literal"><span class="pre">time</span></code> 对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-20"><a class="reference internal" href="datetime.html#tzinfo-objects">8.1.6. <code class="docutils literal"><span class="pre">tzinfo</span></code> 对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-21"><a class="reference internal" href="datetime.html#timezone-objects">8.1.7. <code class="docutils literal"><span class="pre">timezone</span></code> 对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-22"><a class="reference internal" href="datetime.html#strftime-and-strptime-behavior">8.1.8. <code class="docutils literal"><span class="pre">strftime()</span></code><code class="docutils literal"><span class="pre">strptime()</span></code>的行为</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-24"><a class="reference internal" href="calendar.html">8.2. <code class="docutils literal"><span class="pre">calendar</span></code> - 一般日历相关功能</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-38"><a class="reference internal" href="collections.html">8.3. <code class="docutils literal"><span class="pre">collections</span></code> - 容器数据类型</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-26"><a class="reference internal" href="collections.html#chainmap-objects">8.3.1. <code class="docutils literal"><span class="pre">ChainMap</span></code>对象</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-25"><a class="reference internal" href="collections.html#chainmap-examples-and-recipes">8.3.1.1. <code class="docutils literal"><span class="pre">ChainMap</span></code>示例和配方</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-27"><a class="reference internal" href="collections.html#counter-objects">8.3.2. <code class="docutils literal"><span class="pre">Counter</span></code>对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-29"><a class="reference internal" href="collections.html#deque-objects">8.3.3. <code class="docutils literal"><span class="pre">deque</span></code>对象</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-28"><a class="reference internal" href="collections.html#deque-recipes">8.3.3.1. <code class="docutils literal"><span class="pre">deque</span></code>食谱</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-31"><a class="reference internal" href="collections.html#defaultdict-objects">8.3.4. <code class="docutils literal"><span class="pre">defaultdict</span></code>对象</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-30"><a class="reference internal" href="collections.html#defaultdict-examples">8.3.4.1. <code class="docutils literal"><span class="pre">defaultdict</span></code>示例</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-32"><a class="reference internal" href="collections.html#namedtuple-factory-function-for-tuples-with-named-fields">8.3.5. <code class="docutils literal"><span class="pre">namedtuple()</span></code>具有命名字段的元组的工厂函数</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-34"><a class="reference internal" href="collections.html#ordereddict-objects">8.3.6. <code class="docutils literal"><span class="pre">OrderedDict</span></code>对象</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-33"><a class="reference internal" href="collections.html#ordereddict-examples-and-recipes">8.3.6.1. <code class="docutils literal"><span class="pre">OrderedDict</span></code>示例和食谱</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-35"><a class="reference internal" href="collections.html#userdict-objects">8.3.7. <code class="docutils literal"><span class="pre">UserDict</span></code>对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-36"><a class="reference internal" href="collections.html#userlist-objects">8.3.8. <code class="docutils literal"><span class="pre">UserList</span></code>对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-37"><a class="reference internal" href="collections.html#userstring-objects">8.3.9. <code class="docutils literal"><span class="pre">UserString</span></code>对象</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-40"><a class="reference internal" href="collections.abc.html">8.4. <code class="docutils literal"><span class="pre">collections.abc</span></code> - 容器的抽象基类</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-39"><a class="reference internal" href="collections.abc.html#collections-abstract-base-classes">8.4.1.容器抽象基类</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-44"><a class="reference internal" href="heapq.html">8.5. <code class="docutils literal"><span class="pre">heapq</span></code> - 堆队列算法</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-41"><a class="reference internal" href="heapq.html#basic-examples">8.5.1.基本示例</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-42"><a class="reference internal" href="heapq.html#priority-queue-implementation-notes">8.5.2.优先级队列实现说明</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-43"><a class="reference internal" href="heapq.html#theory">8.5.3.理论</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-47"><a class="reference internal" href="bisect.html">8.6. <code class="docutils literal"><span class="pre">bisect</span></code> - 数组对分算法</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-45"><a class="reference internal" href="bisect.html#searching-sorted-lists">8.6.1.搜索排序列表</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-46"><a class="reference internal" href="bisect.html#other-examples">8.6.2.其他示例</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-48"><a class="reference internal" href="array.html">8.7. <code class="docutils literal"><span class="pre">array</span></code> - 数值的有效数组</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-53"><a class="reference internal" href="weakref.html">8.8. <code class="docutils literal"><span class="pre">weakref</span></code> - 弱参考</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-49"><a class="reference internal" href="weakref.html#weak-reference-objects">8.8.1.弱参考对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-50"><a class="reference internal" href="weakref.html#example">8.8.2.示例</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-51"><a class="reference internal" href="weakref.html#finalizer-objects">8.8.3. Finalizer对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-52"><a class="reference internal" href="weakref.html#comparing-finalizers-with-del-methods">8.8.4.比较终结符与<code class="docutils literal"><span class="pre">__del__()</span></code>方法</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-58"><a class="reference internal" href="types.html">8.9. <code class="docutils literal"><span class="pre">types</span></code> - 内建类型的动态类型创建和名称</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-54"><a class="reference internal" href="types.html#dynamic-type-creation">8.9.1.动态类型创建</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-55"><a class="reference internal" href="types.html#standard-interpreter-types">8.9.2.标准解释器类型</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-56"><a class="reference internal" href="types.html#additional-utility-classes-and-functions">8.9.3.其他实用程序类和函数</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-57"><a class="reference internal" href="types.html#coroutine-utility-functions">8.9.4.协程实用函数</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-59"><a class="reference internal" href="copy.html">8.10. <code class="docutils literal"><span class="pre">copy</span></code> - 浅层和深层复制操作</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-62"><a class="reference internal" href="pprint.html">8.11. <code class="docutils literal"><span class="pre">pprint</span></code> - 数据漂亮打印机</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-60"><a class="reference internal" href="pprint.html#prettyprinter-objects">8.11.1. PrettyPrinter对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-61"><a class="reference internal" href="pprint.html#example">8.11.2.示例</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-65"><a class="reference internal" href="reprlib.html">8.12. <code class="docutils literal"><span class="pre">reprlib</span></code> - 备用<code class="docutils literal"><span class="pre">repr()</span></code>实施</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-63"><a class="reference internal" href="reprlib.html#repr-objects">8.12.1. Repr对象</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-64"><a class="reference internal" href="reprlib.html#subclassing-repr-objects">8.12.2.子类化对象</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-89"><a class="reference internal" href="enum.html">8.13. <code class="docutils literal"><span class="pre">enum</span></code> - 支持枚举</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-66"><a class="reference internal" href="enum.html#module-contents">8.13.1.模块内容</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-67"><a class="reference internal" href="enum.html#creating-an-enum">8.13.2.创建枚举</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-68"><a class="reference internal" href="enum.html#programmatic-access-to-enumeration-members-and-their-attributes">8.13.3.对枚举成员及其属性的编程访问</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-69"><a class="reference internal" href="enum.html#duplicating-enum-members-and-values">8.13.4.复制枚举成员和值</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-70"><a class="reference internal" href="enum.html#ensuring-unique-enumeration-values">8.13.5.确保唯一的枚举值</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-71"><a class="reference internal" href="enum.html#iteration">8.13.6.迭代</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-72"><a class="reference internal" href="enum.html#comparisons">8.13.7.比较</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-73"><a class="reference internal" href="enum.html#allowed-members-and-attributes-of-enumerations">8.13.8.允许枚举的成员和属性</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-74"><a class="reference internal" href="enum.html#restricted-subclassing-of-enumerations">8.13.9.枚举的子类化</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-75"><a class="reference internal" href="enum.html#pickling">8.13.10.酸洗</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-76"><a class="reference internal" href="enum.html#functional-api">8.13.11.功能API</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-79"><a class="reference internal" href="enum.html#derived-enumerations">8.13.12.派生枚举</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-77"><a class="reference internal" href="enum.html#intenum">8.13.12.1. IntEnum</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-78"><a class="reference internal" href="enum.html#others">8.13.12.2.其他</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-84"><a class="reference internal" href="enum.html#interesting-examples">8.13.13.有趣的示例</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-80"><a class="reference internal" href="enum.html#autonumber">8.13.13.1.自动编号</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-81"><a class="reference internal" href="enum.html#orderedenum">8.13.13.2. OrderedEnum</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-82"><a class="reference internal" href="enum.html#duplicatefreeenum">8.13.13.3. DuplicateFreeEnum</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-83"><a class="reference internal" href="enum.html#planet">8.13.13.4.星球</a></span></li></ul></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-88"><a class="reference internal" href="enum.html#how-are-enums-different">8.13.14.如何不同?</a></span><ul><li class="toctree-l3"><span class="yiyi-st" id="yiyi-85"><a class="reference internal" href="enum.html#enum-classes">8.13.14.1.枚举类</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-86"><a class="reference internal" href="enum.html#enum-members-aka-instances">8.13.14.2.枚举成员(又名实例)</a></span></li><li class="toctree-l3"><span class="yiyi-st" id="yiyi-87"><a class="reference internal" href="enum.html#finer-points">8.13.14.3.精细点</a></span></li></ul></li></ul></li></ul></div></div></div>