409 lines
21 KiB
HTML
409 lines
21 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
|
||
<head>
|
||
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||
|
||
<title>具体的对象层 — Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
|
||
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||
<script src="../_static/jquery.js"></script>
|
||
<script src="../_static/underscore.js"></script>
|
||
<script src="../_static/doctools.js"></script>
|
||
<script src="../_static/language_data.js"></script>
|
||
<script src="../_static/translations.js"></script>
|
||
|
||
<script src="../_static/sidebar.js"></script>
|
||
|
||
<link rel="search" type="application/opensearchdescription+xml"
|
||
title="在 Python 3.8.20 文档 中搜索"
|
||
href="../_static/opensearch.xml"/>
|
||
<link rel="author" title="关于这些文档" href="../about.html" />
|
||
<link rel="index" title="索引" href="../genindex.html" />
|
||
<link rel="search" title="搜索" href="../search.html" />
|
||
<link rel="copyright" title="版权所有" href="../copyright.html" />
|
||
<link rel="next" title="类型对象" href="type.html" />
|
||
<link rel="prev" title="旧缓冲协议" href="objbuffer.html" />
|
||
<link rel="canonical" href="https://docs.python.org/3/c-api/concrete.html" />
|
||
|
||
|
||
|
||
|
||
|
||
<style>
|
||
@media only screen {
|
||
table.full-width-table {
|
||
width: 100%;
|
||
}
|
||
}
|
||
</style>
|
||
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
|
||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||
<script type="text/javascript" src="../_static/menu.js"></script>
|
||
|
||
</head>
|
||
<body>
|
||
<div class="mobile-nav">
|
||
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
|
||
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
|
||
<label for="menuToggler" class="toggler__label">
|
||
<span></span>
|
||
</label>
|
||
<nav class="nav-content" role="navigation">
|
||
<a href="https://www.python.org/" class="nav-logo">
|
||
<img src="../_static/py.svg" alt="Logo"/>
|
||
</a>
|
||
<div class="version_switcher_placeholder"></div>
|
||
<form role="search" class="search" action="../search.html" method="get">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
|
||
<path fill-rule="nonzero"
|
||
d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path>
|
||
</svg>
|
||
<input type="text" name="q" aria-label="快速搜索"/>
|
||
<input type="submit" value="转向"/>
|
||
</form>
|
||
</nav>
|
||
<div class="menu-wrapper">
|
||
<nav class="menu" role="navigation" aria-label="main navigation">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<h3><a href="../contents.html">目录</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">具体的对象层</a><ul>
|
||
<li><a class="reference internal" href="#fundamental-objects">基本对象</a></li>
|
||
<li><a class="reference internal" href="#numeric-objects">数值对象</a></li>
|
||
<li><a class="reference internal" href="#sequence-objects">序列对象</a></li>
|
||
<li><a class="reference internal" href="#container-objects">容器对象</a></li>
|
||
<li><a class="reference internal" href="#function-objects">函数对象</a></li>
|
||
<li><a class="reference internal" href="#other-objects">其他对象</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="objbuffer.html"
|
||
title="上一章">旧缓冲协议</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="type.html"
|
||
title="下一章">类型对象</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>本页</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">报告 Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/3.8/Doc/c-api/concrete.rst"
|
||
rel="nofollow">显示源代码
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</nav>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
|
||
这个文档所针对的是一个已不再受支持的 Python 旧版本。
|
||
你应当升级版本,并阅读
|
||
<a href="/3/c-api/concrete.html"> Python 当前稳定版本的文档</a>.
|
||
</div>
|
||
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>导航</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="总目录"
|
||
accesskey="I">索引</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python 模块索引"
|
||
>模块</a> |</li>
|
||
<li class="right" >
|
||
<a href="type.html" title="类型对象"
|
||
accesskey="N">下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="objbuffer.html" title="旧缓冲协议"
|
||
accesskey="P">上一页</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.8.20 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python/C API 参考手册</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
||
<input type="submit" value="转向" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="concrete-objects-layer">
|
||
<span id="concrete"></span><h1>具体的对象层<a class="headerlink" href="#concrete-objects-layer" title="永久链接至标题">¶</a></h1>
|
||
<p>本章中的函数特定于某些 Python 对象类型。 将错误类型的对象传递给它们并不是一个好主意;如果您从 Python 程序接收到一个对象,但不确定它是否具有正确的类型,则必须首先执行类型检查;例如,要检查对象是否为字典,请使用 <a class="reference internal" href="dict.html#c.PyDict_Check" title="PyDict_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_Check()</span></code></a>。 本章的结构类似于 Python 对象类型的“家族树”。</p>
|
||
<div class="admonition warning">
|
||
<p class="admonition-title">警告</p>
|
||
<p>虽然本章所描述的函数会仔细检查传入对象的类型,但是其中许多函数不会检查传入的对象是否为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 允许传入 <code class="docutils literal notranslate"><span class="pre">NULL</span></code> 可能导致内存访问冲突和解释器的立即终止。</p>
|
||
</div>
|
||
<section id="fundamental-objects">
|
||
<span id="fundamental"></span><h2>基本对象<a class="headerlink" href="#fundamental-objects" title="永久链接至标题">¶</a></h2>
|
||
<p>本节描述Python类型对象和单一实例对象 象None。</p>
|
||
<div class="toctree-wrapper compound">
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="type.html">类型对象</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="type.html#creating-heap-allocated-types">创建堆分配类型</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="none.html"><code class="docutils literal notranslate"><span class="pre">None</span></code> 对象</a></li>
|
||
</ul>
|
||
</div>
|
||
</section>
|
||
<section id="numeric-objects">
|
||
<span id="numericobjects"></span><h2>数值对象<a class="headerlink" href="#numeric-objects" title="永久链接至标题">¶</a></h2>
|
||
<div class="toctree-wrapper compound" id="index-0">
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="long.html">整数型对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="bool.html">布尔对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="float.html">浮点数对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="complex.html">复数对象</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="complex.html#complex-numbers-as-c-structures">表示复数的C结构体</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="complex.html#complex-numbers-as-python-objects">表示复数的Python对象</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</section>
|
||
<section id="sequence-objects">
|
||
<span id="sequenceobjects"></span><h2>序列对象<a class="headerlink" href="#sequence-objects" title="永久链接至标题">¶</a></h2>
|
||
<p id="index-1">序列对象的一般操作在前一章中讨论过;本节介绍Python语言固有的特定类型的序列对象。</p>
|
||
<div class="toctree-wrapper compound">
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="bytes.html">bytes 对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="bytearray.html">字节数组对象</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="bytearray.html#type-check-macros">类型检查宏</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="bytearray.html#direct-api-functions">直接 API 函数</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="bytearray.html#macros">宏</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="unicode.html">Unicode对象和编解码器</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="unicode.html#unicode-objects">Unicode对象</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#unicode-type">Unicode类型</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#unicode-character-properties">Unicode字符属性</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#creating-and-accessing-unicode-strings">创建和访问 Unicode 字符串</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#deprecated-py-unicode-apis">已弃用的 Py_UNICODE API</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#locale-encoding">语言区域编码格式</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#file-system-encoding">文件系统编码格式</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#wchar-t-support">wchar_t 支持</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="unicode.html#built-in-codecs">内置编解码器</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#generic-codecs">泛型编解码器</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#utf-8-codecs">UTF-8 编解码器</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#utf-32-codecs">UTF-32 编解码器</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#utf-16-codecs">UTF-16 编解码器</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#utf-7-codecs">UTF-7 编解码器</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#unicode-escape-codecs">Unicode-Escape 编解码器</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#raw-unicode-escape-codecs">Raw-Unicode-Escape 编解码器</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#latin-1-codecs">Latin-1 编解码器</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#ascii-codecs">ASCII 编解码器</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#character-map-codecs">字符映射编解码器</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#mbcs-codecs-for-windows">Windows 中的 MBCS 编解码器</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unicode.html#methods-slots">方法和槽位</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="unicode.html#methods-and-slot-functions">方法与槽位函数</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="tuple.html">元组对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="tuple.html#struct-sequence-objects">结构序列对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="list.html">列表对象</a></li>
|
||
</ul>
|
||
</div>
|
||
</section>
|
||
<section id="container-objects">
|
||
<span id="mapobjects"></span><h2>容器对象<a class="headerlink" href="#container-objects" title="永久链接至标题">¶</a></h2>
|
||
<div class="toctree-wrapper compound" id="index-2">
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="dict.html">字典对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="set.html">集合对象</a></li>
|
||
</ul>
|
||
</div>
|
||
</section>
|
||
<section id="function-objects">
|
||
<span id="otherobjects"></span><h2>函数对象<a class="headerlink" href="#function-objects" title="永久链接至标题">¶</a></h2>
|
||
<div class="toctree-wrapper compound">
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="function.html">函数对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="method.html">实例方法对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="method.html#method-objects">方法对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="cell.html">Cell 对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="code.html">代码对象</a></li>
|
||
</ul>
|
||
</div>
|
||
</section>
|
||
<section id="other-objects">
|
||
<h2>其他对象<a class="headerlink" href="#other-objects" title="永久链接至标题">¶</a></h2>
|
||
<div class="toctree-wrapper compound">
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="file.html">文件对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="module.html">模块对象</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="module.html#initializing-c-modules">初始化 C 模块</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="module.html#single-phase-initialization">Single-phase initialization</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="module.html#multi-phase-initialization">Multi-phase initialization</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="module.html#low-level-module-creation-functions">Low-level module creation functions</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="module.html#support-functions">Support functions</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="module.html#module-lookup">Module lookup</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="iterator.html">迭代器对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="descriptor.html">描述符对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="slice.html">切片对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="slice.html#ellipsis-object">Ellipsis 对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="memoryview.html">MemoryView 对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="weakref.html">弱引用对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="capsule.html">胶囊</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="gen.html">生成器对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="coro.html">协程对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="contextvars.html">上下文变量对象</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="datetime.html">DateTime 对象</a></li>
|
||
</ul>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<h3><a href="../contents.html">目录</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">具体的对象层</a><ul>
|
||
<li><a class="reference internal" href="#fundamental-objects">基本对象</a></li>
|
||
<li><a class="reference internal" href="#numeric-objects">数值对象</a></li>
|
||
<li><a class="reference internal" href="#sequence-objects">序列对象</a></li>
|
||
<li><a class="reference internal" href="#container-objects">容器对象</a></li>
|
||
<li><a class="reference internal" href="#function-objects">函数对象</a></li>
|
||
<li><a class="reference internal" href="#other-objects">其他对象</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="objbuffer.html"
|
||
title="上一章">旧缓冲协议</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="type.html"
|
||
title="下一章">类型对象</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>本页</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">报告 Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/3.8/Doc/c-api/concrete.rst"
|
||
rel="nofollow">显示源代码
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>导航</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="总目录"
|
||
>索引</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python 模块索引"
|
||
>模块</a> |</li>
|
||
<li class="right" >
|
||
<a href="type.html" title="类型对象"
|
||
>下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="objbuffer.html" title="旧缓冲协议"
|
||
>上一页</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.8.20 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Python/C API 参考手册</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
||
<input type="submit" value="转向" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
<div class="footer">
|
||
© <a href="../copyright.html">版权所有</a> 2001-2024, Python Software Foundation.
|
||
<br />
|
||
This page is licensed under the Python Software Foundation License Version 2.
|
||
<br />
|
||
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
|
||
<br />
|
||
|
||
<br />
|
||
|
||
The Python Software Foundation is a non-profit corporation.
|
||
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
||
<br />
|
||
<br />
|
||
|
||
最后更新于 12月 09, 2024.
|
||
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
|
||
<br />
|
||
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
|
||
</div>
|
||
|
||
</body>
|
||
</html> |