python-project/python-3.7.4-docs-html/library/constants.html

293 lines
17 KiB
HTML

2019-07-15 11:16:41 +07:00
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Built-in Constants &#8212; Python 3.7.4 documentation</title>
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/language_data.js"></script>
<script type="text/javascript" src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.7.4 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="Built-in Types" href="stdtypes.html" />
<link rel="prev" title="Built-in Functions" href="functions.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
<link rel="canonical" href="https://docs.python.org/3/library/constants.html" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/switchers.js"></script>
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="stdtypes.html" title="Built-in Types"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="functions.html" title="Built-in Functions"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li>
<span class="language_switcher_placeholder">en</span>
<span class="version_switcher_placeholder">3.7.4</span>
<a href="../index.html">Documentation </a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">The Python Standard Library</a> &#187;</li>
<li class="right">
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="built-in-constants">
<span id="built-in-consts"></span><h1>Built-in Constants<a class="headerlink" href="#built-in-constants" title="Permalink to this headline"></a></h1>
<p>A small number of constants live in the built-in namespace. They are:</p>
<dl class="data">
<dt id="False">
<code class="descname">False</code><a class="headerlink" href="#False" title="Permalink to this definition"></a></dt>
<dd><p>The false value of the <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> type. Assignments to <code class="docutils literal notranslate"><span class="pre">False</span></code>
are illegal and raise a <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="descname">True</code><a class="headerlink" href="#True" title="Permalink to this definition"></a></dt>
<dd><p>The true value of the <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> type. Assignments to <code class="docutils literal notranslate"><span class="pre">True</span></code>
are illegal and raise a <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="descname">None</code><a class="headerlink" href="#None" title="Permalink to this definition"></a></dt>
<dd><p>The sole value of the type <code class="docutils literal notranslate"><span class="pre">NoneType</span></code>. <code class="docutils literal notranslate"><span class="pre">None</span></code> is frequently used to
represent the absence of a value, as when default arguments are not passed to a
function. Assignments to <code class="docutils literal notranslate"><span class="pre">None</span></code> are illegal and raise a <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="descname">NotImplemented</code><a class="headerlink" href="#NotImplemented" title="Permalink to this definition"></a></dt>
<dd><p>Special value which should be returned by the binary special methods
(e.g. <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>, <a class="reference internal" href="../reference/datamodel.html#object.__add__" title="object.__add__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__add__()</span></code></a>, <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>,
etc.) to indicate that the operation is not implemented with respect to
the other type; may be returned by the in-place binary special methods
(e.g. <a class="reference internal" href="../reference/datamodel.html#object.__imul__" title="object.__imul__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__imul__()</span></code></a>, <a class="reference internal" href="../reference/datamodel.html#object.__iand__" title="object.__iand__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__iand__()</span></code></a>, etc.) for the same purpose.
Its truth value is true.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>When a binary (or in-place) method returns <code class="docutils literal notranslate"><span class="pre">NotImplemented</span></code> the
interpreter will try the reflected operation on the other type (or some
other fallback, depending on the operator). If all attempts return
<code class="docutils literal notranslate"><span class="pre">NotImplemented</span></code>, the interpreter will raise an appropriate exception.
Incorrectly returning <code class="docutils literal notranslate"><span class="pre">NotImplemented</span></code> will result in a misleading
error message or the <code class="docutils literal notranslate"><span class="pre">NotImplemented</span></code> value being returned to Python code.</p>
<p>See <a class="reference internal" href="numbers.html#implementing-the-arithmetic-operations"><span class="std std-ref">Implementing the arithmetic operations</span></a> for examples.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p><code class="docutils literal notranslate"><span class="pre">NotImplementedError</span></code> and <code class="docutils literal notranslate"><span class="pre">NotImplemented</span></code> are not interchangeable,
even though they have similar names and purposes.
See <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> for details on when to use it.</p>
</div>
</dd></dl>
<span class="target" id="index-0"></span><dl class="data">
<dt id="Ellipsis">
<code class="descname">Ellipsis</code><a class="headerlink" href="#Ellipsis" title="Permalink to this definition"></a></dt>
<dd><p>The same as the ellipsis literal “<code class="docutils literal notranslate"><span class="pre">...</span></code>”. Special value used mostly in conjunction
with extended slicing syntax for user-defined container data types.</p>
</dd></dl>
<dl class="data">
<dt id="__debug__">
<code class="descname">__debug__</code><a class="headerlink" href="#__debug__" title="Permalink to this definition"></a></dt>
<dd><p>This constant is true if Python was not started with an <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> option.
See also the <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> statement.</p>
</dd></dl>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The names <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> and <a class="reference internal" href="#__debug__" title="__debug__"><code class="xref py py-data docutils literal notranslate"><span class="pre">__debug__</span></code></a>
cannot be reassigned (assignments to them, even as an attribute name, raise
<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>), so they can be considered “true” constants.</p>
</div>
<div class="section" id="constants-added-by-the-site-module">
<h2>Constants added by the <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> module<a class="headerlink" href="#constants-added-by-the-site-module" title="Permalink to this headline"></a></h2>
<p>The <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> module (which is imported automatically during startup, except
if the <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> command-line option is given) adds several constants to the
built-in namespace. They are useful for the interactive interpreter shell and
should not be used in programs.</p>
<dl class="data">
<dt id="quit">
<code class="descname">quit</code><span class="sig-paren">(</span><em>code=None</em><span class="sig-paren">)</span><a class="headerlink" href="#quit" title="Permalink to this definition"></a></dt>
<dt id="exit">
<code class="descname">exit</code><span class="sig-paren">(</span><em>code=None</em><span class="sig-paren">)</span><a class="headerlink" href="#exit" title="Permalink to this definition"></a></dt>
<dd><p>Objects that when printed, print a message like “Use quit() or Ctrl-D
(i.e. EOF) to exit”, and when called, raise <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> with the
specified exit code.</p>
</dd></dl>
<dl class="data">
<dt id="copyright">
<code class="descname">copyright</code><a class="headerlink" href="#copyright" title="Permalink to this definition"></a></dt>
<dt id="credits">
<code class="descname">credits</code><a class="headerlink" href="#credits" title="Permalink to this definition"></a></dt>
<dd><p>Objects that when printed or called, print the text of copyright or
credits, respectively.</p>
</dd></dl>
<dl class="data">
<dt id="license">
<code class="descname">license</code><a class="headerlink" href="#license" title="Permalink to this definition"></a></dt>
<dd><p>Object that when printed, prints the message “Type license() to see the
full license text”, and when called, displays the full license text in a
pager-like fashion (one screen at a time).</p>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Built-in Constants</a><ul>
<li><a class="reference internal" href="#constants-added-by-the-site-module">Constants added by the <code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code> module</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="functions.html"
title="previous chapter">Built-in Functions</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="stdtypes.html"
title="next chapter">Built-in Types</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.7/Doc/library/constants.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="stdtypes.html" title="Built-in Types"
>next</a> |</li>
<li class="right" >
<a href="functions.html" title="Built-in Functions"
>previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li>
<span class="language_switcher_placeholder">en</span>
<span class="version_switcher_placeholder">3.7.4</span>
<a href="../index.html">Documentation </a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
<li class="right">
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">Copyright</a> 2001-2019, Python Software Foundation.
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
Last updated on Jul 13, 2019.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
</div>
</body>
</html>