344 lines
20 KiB
HTML
344 lines
20 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="stdtypes.html" />
|
||
<link rel="prev" title="内置函数" href="functions.html" />
|
||
<link rel="canonical" href="https://docs.python.org/3/library/constants.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="#constants-added-by-the-site-module">由 <code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code> 模块添加的常量</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="functions.html"
|
||
title="上一章">内置函数</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="stdtypes.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/library/constants.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/library/constants.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="stdtypes.html" title="内置类型"
|
||
accesskey="N">下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="functions.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 标准库</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="built-in-constants">
|
||
<span id="built-in-consts"></span><h1>内置常量<a class="headerlink" href="#built-in-constants" title="永久链接至标题">¶</a></h1>
|
||
<p>有少数的常量存在于内置命名空间中。 它们是:</p>
|
||
<dl class="data">
|
||
<dt id="False">
|
||
<code class="sig-name descname">False</code><a class="headerlink" href="#False" title="永久链接至目标">¶</a></dt>
|
||
<dd><p><a class="reference internal" href="functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a> 类型的假值。 给 <code class="docutils literal notranslate"><span class="pre">False</span></code> 赋值是非法的并会引发 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="True">
|
||
<code class="sig-name descname">True</code><a class="headerlink" href="#True" title="永久链接至目标">¶</a></dt>
|
||
<dd><p><a class="reference internal" href="functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a> 类型的真值。 给 <code class="docutils literal notranslate"><span class="pre">True</span></code> 赋值是非法的并会引发 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="None">
|
||
<code class="sig-name descname">None</code><a class="headerlink" href="#None" title="永久链接至目标">¶</a></dt>
|
||
<dd><p><code class="docutils literal notranslate"><span class="pre">NoneType</span></code> 类型的唯一值。 <code class="docutils literal notranslate"><span class="pre">None</span></code> 经常用于表示缺少值,当因为默认参数未传递给函数时。 给 <code class="docutils literal notranslate"><span class="pre">None</span></code> 赋值是非法的并会引发 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="NotImplemented">
|
||
<code class="sig-name descname">NotImplemented</code><a class="headerlink" href="#NotImplemented" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>二进制特殊方法应返回的特殊值(例如,<a class="reference internal" href="../reference/datamodel.html#object.__eq__" title="object.__eq__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__eq__()</span></code></a>、<a class="reference internal" href="../reference/datamodel.html#object.__lt__" title="object.__lt__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__lt__()</span></code></a>、<code class="xref py py-meth docutils literal notranslate"><span class="pre">__add</span> <span class="pre">__()</span></code>、<a class="reference internal" href="../reference/datamodel.html#object.__rsub__" title="object.__rsub__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__rsub__()</span></code></a> 等)表示操作没有针对其他类型实现;为了相同的目的,可以通过就地二进制特殊方法(例如,<code class="xref py py-meth docutils literal notranslate"><span class="pre">__imul</span> <span class="pre">__()</span></code>、<code class="xref py py-meth docutils literal notranslate"><span class="pre">__</span> <span class="pre">rightnd__()</span></code> 等)返回。 它的逻辑值为真。</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">注解</p>
|
||
<p>当二进制(或就地)方法返回``NotImplemented``时,解释器将尝试对另一种类型(或其他一些回滚操作,取决于运算符)的反射操作。 如果所有尝试都返回``NotImplemented``,则解释器将引发适当的异常。 错误返回的``NotImplemented``将导致误导性错误消息或返回到Python代码中的``NotImplemented``值。</p>
|
||
<p>参见 <a class="reference internal" href="numbers.html#implementing-the-arithmetic-operations"><span class="std std-ref">实现算术运算</span></a> 为例。</p>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">注解</p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">NotImplementedError</span></code> 和 <code class="docutils literal notranslate"><span class="pre">NotImplemented</span></code> 不可互换,即使它们有相似的名称和用途。 有关何时使用它的详细信息,请参阅 <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a>。</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<span class="target" id="index-0"></span><dl class="data">
|
||
<dt id="Ellipsis">
|
||
<code class="sig-name descname">Ellipsis</code><a class="headerlink" href="#Ellipsis" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>与省略号文字字面 “<code class="docutils literal notranslate"><span class="pre">...</span></code>” 相同。 特殊值主要与用户定义的容器数据类型的扩展切片语法结合使用。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="__debug__">
|
||
<code class="sig-name descname">__debug__</code><a class="headerlink" href="#__debug__" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果 Python 没有以 <a class="reference internal" href="../using/cmdline.html#cmdoption-o"><code class="xref std std-option docutils literal notranslate"><span class="pre">-O</span></code></a> 选项启动,则此常量为真值。 另请参见 <a class="reference internal" href="../reference/simple_stmts.html#assert"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">assert</span></code></a> 语句。</p>
|
||
</dd></dl>
|
||
|
||
<div class="admonition note">
|
||
<p class="admonition-title">注解</p>
|
||
<p>变量名 <a class="reference internal" href="#None" title="None"><code class="xref py py-data docutils literal notranslate"><span class="pre">None</span></code></a>,<a class="reference internal" href="#False" title="False"><code class="xref py py-data docutils literal notranslate"><span class="pre">False</span></code></a>,<a class="reference internal" href="#True" title="True"><code class="xref py py-data docutils literal notranslate"><span class="pre">True</span></code></a> 和 <code class="xref py py-data docutils literal notranslate"><span class="pre">__</span> <span class="pre">debug__</span></code> 无法重新赋值(赋值给它们,即使是属性名,将引发 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> ),所以它们可以被认为是“真正的”常数。</p>
|
||
</div>
|
||
<section id="constants-added-by-the-site-module">
|
||
<h2>由 <a class="reference internal" href="site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> 模块添加的常量<a class="headerlink" href="#constants-added-by-the-site-module" title="永久链接至标题">¶</a></h2>
|
||
<p><a class="reference internal" href="site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> 模块(在启动期间自动导入,除非给出 <a class="reference internal" href="../using/cmdline.html#id3"><code class="xref std std-option docutils literal notranslate"><span class="pre">-S</span></code></a> 命令行选项)将几个常量添加到内置命名空间。 它们对交互式解释器 shell 很有用,并且不应在程序中使用。</p>
|
||
<dl class="data">
|
||
<dt id="quit">
|
||
<code class="sig-name descname">quit</code><span class="sig-paren">(</span><em class="sig-param">code=None</em><span class="sig-paren">)</span><a class="headerlink" href="#quit" title="永久链接至目标">¶</a></dt>
|
||
<dt id="exit">
|
||
<code class="sig-name descname">exit</code><span class="sig-paren">(</span><em class="sig-param">code=None</em><span class="sig-paren">)</span><a class="headerlink" href="#exit" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>当打印此对象时,会打印出一条消息,例如“Use quit() or Ctrl-D (i.e. EOF) to exit”,当调用此对象时,将使用指定的退出代码来引发 <a class="reference internal" href="exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemExit</span></code></a>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="copyright">
|
||
<code class="sig-name descname">copyright</code><a class="headerlink" href="#copyright" title="永久链接至目标">¶</a></dt>
|
||
<dt id="credits">
|
||
<code class="sig-name descname">credits</code><a class="headerlink" href="#credits" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>打印或调用的对象分别打印版权或作者的文本。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="data">
|
||
<dt id="license">
|
||
<code class="sig-name descname">license</code><a class="headerlink" href="#license" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>当打印此对象时,会打印出一条消息“Type license() to see the full license text”,当调用此对象时,将以分页形式显示完整的许可证文本(每次显示一屏)。</p>
|
||
</dd></dl>
|
||
|
||
</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="#constants-added-by-the-site-module">由 <code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code> 模块添加的常量</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="functions.html"
|
||
title="上一章">内置函数</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="stdtypes.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/library/constants.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="stdtypes.html" title="内置类型"
|
||
>下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="functions.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 标准库</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> |