1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<span id="built-in-consts"></span><h1>Built-in Constants</h1> <p>A small number of constants live in the built-in namespace. They are:</p> <dl class="py data"> <dt class="sig sig-object py" id="False">
<code>False</code> </dt> <dd>
<p>The false value of the <a class="reference internal" href="functions#bool" title="bool"><code>bool</code></a> type. Assignments to <code>False</code> are illegal and raise a <a class="reference internal" href="exceptions#SyntaxError" title="SyntaxError"><code>SyntaxError</code></a>.</p> </dd>
</dl> <dl class="py data"> <dt class="sig sig-object py" id="True">
<code>True</code> </dt> <dd>
<p>The true value of the <a class="reference internal" href="functions#bool" title="bool"><code>bool</code></a> type. Assignments to <code>True</code> are illegal and raise a <a class="reference internal" href="exceptions#SyntaxError" title="SyntaxError"><code>SyntaxError</code></a>.</p> </dd>
</dl> <dl class="py data"> <dt class="sig sig-object py" id="None">
<code>None</code> </dt> <dd>
<p>An object frequently used to represent the absence of a value, as when default arguments are not passed to a function. Assignments to <code>None</code> are illegal and raise a <a class="reference internal" href="exceptions#SyntaxError" title="SyntaxError"><code>SyntaxError</code></a>. <code>None</code> is the sole instance of the <a class="reference internal" href="types#types.NoneType" title="types.NoneType"><code>NoneType</code></a> type.</p> </dd>
</dl> <dl class="py data"> <dt class="sig sig-object py" id="NotImplemented">
<code>NotImplemented</code> </dt> <dd>
<p>A special value which should be returned by the binary special methods (e.g. <a class="reference internal" href="../reference/datamodel#object.__eq__" title="object.__eq__"><code>__eq__()</code></a>, <a class="reference internal" href="../reference/datamodel#object.__lt__" title="object.__lt__"><code>__lt__()</code></a>, <a class="reference internal" href="../reference/datamodel#object.__add__" title="object.__add__"><code>__add__()</code></a>, <a class="reference internal" href="../reference/datamodel#object.__rsub__" title="object.__rsub__"><code>__rsub__()</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#object.__imul__" title="object.__imul__"><code>__imul__()</code></a>, <a class="reference internal" href="../reference/datamodel#object.__iand__" title="object.__iand__"><code>__iand__()</code></a>, etc.) for the same purpose. It should not be evaluated in a boolean context. <code>NotImplemented</code> is the sole instance of the <a class="reference internal" href="types#types.NotImplementedType" title="types.NotImplementedType"><code>types.NotImplementedType</code></a> type.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>When a binary (or in-place) method returns <code>NotImplemented</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>NotImplemented</code>, the interpreter will raise an appropriate exception. Incorrectly returning <code>NotImplemented</code> will result in a misleading error message or the <code>NotImplemented</code> value being returned to Python code.</p> <p>See <a class="reference internal" href="numbers#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>NotImplementedError</code> and <code>NotImplemented</code> are not interchangeable, even though they have similar names and purposes. See <a class="reference internal" href="exceptions#NotImplementedError" title="NotImplementedError"><code>NotImplementedError</code></a> for details on when to use it.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.9: </span>Evaluating <code>NotImplemented</code> in a boolean context is deprecated. While it currently evaluates as true, it will emit a <a class="reference internal" href="exceptions#DeprecationWarning" title="DeprecationWarning"><code>DeprecationWarning</code></a>. It will raise a <a class="reference internal" href="exceptions#TypeError" title="TypeError"><code>TypeError</code></a> in a future version of Python.</p> </div> </dd>
</dl> <span class="target" id="index-0"></span><dl class="py data"> <dt class="sig sig-object py" id="Ellipsis">
<code>Ellipsis</code> </dt> <dd>
<p>The same as the ellipsis literal “<code>...</code>”. Special value used mostly in conjunction with extended slicing syntax for user-defined container data types. <code>Ellipsis</code> is the sole instance of the <a class="reference internal" href="types#types.EllipsisType" title="types.EllipsisType"><code>types.EllipsisType</code></a> type.</p> </dd>
</dl> <dl class="py data"> <dt class="sig sig-object py" id="debug__">
<code>__debug__</code> </dt> <dd>
<p>This constant is true if Python was not started with an <a class="reference internal" href="../using/cmdline#cmdoption-O"><code>-O</code></a> option. See also the <a class="reference internal" href="../reference/simple_stmts#assert"><code>assert</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>None</code></a>, <a class="reference internal" href="#False" title="False"><code>False</code></a>, <a class="reference internal" href="#True" title="True"><code>True</code></a> and <a class="reference internal" href="#debug__" title="__debug__"><code>__debug__</code></a> cannot be reassigned (assignments to them, even as an attribute name, raise <a class="reference internal" href="exceptions#SyntaxError" title="SyntaxError"><code>SyntaxError</code></a>), so they can be considered “true” constants.</p> </div> <section id="constants-added-by-the-site-module"> <h2>Constants added by the site module</h2> <p>The <a class="reference internal" href="site#module-site" title="site: Module responsible for site-specific configuration."><code>site</code></a> module (which is imported automatically during startup, except if the <a class="reference internal" href="../using/cmdline#cmdoption-S"><code>-S</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="py data"> <dt class="sig sig-object py" id="quit">
<code>quit(code=None)</code> </dt> <dt class="sig sig-object py" id="exit">
<code>exit(code=None)</code> </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#SystemExit" title="SystemExit"><code>SystemExit</code></a> with the specified exit code.</p> </dd>
</dl> <dl class="py data"> <dt class="sig sig-object py" id="copyright">
<code>copyright</code> </dt> <dt class="sig sig-object py" id="credits">
<code>credits</code> </dt> <dd>
<p>Objects that when printed or called, print the text of copyright or credits, respectively.</p> </dd>
</dl> <dl class="py data"> <dt class="sig sig-object py" id="license">
<code>license</code> </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> </section> <div class="_attribution">
<p class="_attribution-p">
© 2001–2023 Python Software Foundation<br>Licensed under the PSF License.<br>
<a href="https://docs.python.org/3.12/library/constants.html" class="_attribution-link">https://docs.python.org/3.12/library/constants.html</a>
</p>
</div>
|