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

1 line
9.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="body" role="main"><div class="section" id="built-in-constants"><h1><span class="yiyi-st" id="yiyi-9">3.</span><span class="yiyi-st" id="yiyi-10">内建常量 </span></h1><p><span class="yiyi-st" id="yiyi-11">内置的命名空间中存在少数几个常量。</span><span class="yiyi-st" id="yiyi-12">它们是:</span></p><dl class="data"><dt id="False"><span class="yiyi-st" id="yiyi-13"><code class="descname">False</code> </span></dt><dd><p><span class="yiyi-st" id="yiyi-14"><a class="reference internal" href="functions.html#bool" title="bool"><code class="xref py py-class docutils literal"><span class="pre">bool</span></code></a>类型的假值。</span><span class="yiyi-st" id="yiyi-15"><code class="docutils literal"><span class="pre">False</span></code> 的赋值是非法的将会导致 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal"><span class="pre">SyntaxError</span></code></a></span></p></dd></dl><dl class="data"><dt id="True"><span class="yiyi-st" id="yiyi-16"><code class="descname">True</code> </span></dt><dd><p><span class="yiyi-st" id="yiyi-17"><a class="reference internal" href="functions.html#bool" title="bool"><code class="xref py py-class docutils literal"><span class="pre">bool</span></code></a>类型的真值。</span><span class="yiyi-st" id="yiyi-18"><code class="docutils literal"><span class="pre">True</span></code> 的赋值是非法的将会导致<a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal"><span class="pre">SyntaxError</span></code></a></span></p></dd></dl><dl class="data"><dt id="None"><span class="yiyi-st" id="yiyi-19"><code class="descname">None</code> </span></dt><dd><p><span class="yiyi-st" id="yiyi-20"><code class="docutils literal"><span class="pre">NoneType</span></code> 类型的唯一值。</span><span class="yiyi-st" id="yiyi-21"><code class="docutils literal"><span class="pre">None</span></code> 常用来表示缺省值,当函数的参数并没有被传入时作为默认参数传入。</span><span class="yiyi-st" id="yiyi-22"><code class="docutils literal"><span class="pre">None</span></code> 赋值是非法的将会导致 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal"><span class="pre">SyntaxError</span></code></a></span></p></dd></dl><dl class="data"><dt id="NotImplemented"><span class="yiyi-st" id="yiyi-23"><code class="descname">NotImplemented</code></span></dt><dd><p><span class="yiyi-st" id="yiyi-24">应该由特殊的二元方法返回的特殊值(例如</span><span class="yiyi-st" id="yiyi-25"><a class="reference internal" href="../reference/datamodel.html#object.__eq__" title="object.__eq__"><code class="xref py py-meth docutils literal"><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"><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"><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"><span class="pre">__rsub__()</span></code></a>等)</span><span class="yiyi-st" id="yiyi-26">以指示没有相对于另一类型实现所述操作;可以通过就地二进制特殊方法(例如,</span><span class="yiyi-st" id="yiyi-27"><a class="reference internal" href="../reference/datamodel.html#object.__imul__" title="object.__imul__"><code class="xref py py-meth docutils literal"><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"><span class="pre">__iand__()</span></code></a>等)</span><span class="yiyi-st" id="yiyi-28">为同一目的。</span><span class="yiyi-st" id="yiyi-29">它的真值是True。</span></p></dd></dl><div class="admonition note"><p class="first admonition-title"><span class="yiyi-st" id="yiyi-30">注意</span></p><p><span class="yiyi-st" id="yiyi-31">当返回<code class="docutils literal"><span class="pre">NotImplemented</span></code>时,解释器将根据运算符尝试其他类型的反射操作或其他一些返回。</span><span class="yiyi-st" id="yiyi-32">如果所有尝试的操作返回<code class="docutils literal"><span class="pre">NotImplemented</span></code>,解释器将引发一个适当的异常。</span></p><p class="last"><span class="yiyi-st" id="yiyi-33">有关详细信息,请参见<a class="reference internal" href="numbers.html#implementing-the-arithmetic-operations"><span>Implementing the arithmetic operations</span></a></span></p></div><dl class="data"><dt id="Ellipsis"><span class="yiyi-st" id="yiyi-34"><code class="descname">Ellipsis</code></span></dt><dd><p><span class="yiyi-st" id="yiyi-35"><code class="docutils literal"><span class="pre">...</span></code>相同。特殊值,主要与用户定义的容器数据类型的扩展切片语法结合使用。</span></p></dd></dl><dl class="data"><dt id="__debug__"><span class="yiyi-st" id="yiyi-36"><code class="descname">__debug__</code></span></dt><dd><p><span class="yiyi-st" id="yiyi-37">如果Python未使用<a class="reference internal" href="../using/cmdline.html#cmdoption-O"><code class="xref std std-option docutils literal"><span class="pre">-O</span></code></a>选项启动则此常数为true。</span><span class="yiyi-st" id="yiyi-38">另请参见<a class="reference internal" href="../reference/simple_stmts.html#assert"><code class="xref std std-keyword docutils literal"><span class="pre">assert</span></code></a>语句。</span></p></dd></dl><div class="admonition note"><p class="first admonition-title"><span class="yiyi-st" id="yiyi-39">注意</span></p><p class="last"><span class="yiyi-st" id="yiyi-40">名称<a class="reference internal" href="#None" title="None"><code class="xref py py-data docutils literal"><span class="pre">None</span></code></a><a class="reference internal" href="#False" title="False"><code class="xref py py-data docutils literal"><span class="pre">False</span></code></a><a class="reference internal" href="#True" title="True"><code class="xref py py-data docutils literal"><span class="pre">True</span></code></a><a class="reference internal" href="#__debug__" title="__debug__"><code class="xref py py-data docutils literal"><span class="pre">__debug__</span></code></a>不能重新赋值(给它们赋值,即使作为属性的名称,也会引发<a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal"><span class="pre">SyntaxError</span></code></a>),因此它们可以被认为是“真正的”常量。</span></p></div><div class="section" id="constants-added-by-the-site-module"><h2><span class="yiyi-st" id="yiyi-41">3.1.</span><span class="yiyi-st" id="yiyi-42"><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"><span class="pre">site</span></code></a>模块添加的常量</span></h2><p><span class="yiyi-st" id="yiyi-43"><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"><span class="pre">site</span></code></a>模块(在启动期间自动导入,除非给出了<a class="reference internal" href="../using/cmdline.html#cmdoption-S"><code class="xref std std-option docutils literal"><span class="pre">-S</span></code></a>命令行选项)向内置命名空间添加了几个常量。</span><span class="yiyi-st" id="yiyi-44">它们对交互解释器的shell非常有帮助以并且不应该在程序中使用.</span></p><dl class="data"><dt id="quit"><span class="yiyi-st" id="yiyi-45"><code class="descname">quit</code><span class="sig-paren">(</span><em>code=None</em><span class="sig-paren">)</span></span></dt><dt id="exit"><span class="yiyi-st" id="yiyi-46"><code class="descname">exit</code><span class="sig-paren">(</span><em>code=None</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-47">打印时打印对象,打印一条消息,如“退出()”或Ctrl-D即“</span><span class="yiyi-st" id="yiyi-48">EOF退出并且在调用时使用指定的退出代码提升<a class="reference internal" href="exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal"><span class="pre">SystemExit</span></code></a></span></p></dd></dl><dl class="data"><dt id="copyright"><span class="yiyi-st" id="yiyi-49"><code class="descname">copyright</code></span></dt><dt id="license"><span class="yiyi-st" id="yiyi-50"><code class="descname">license</code></span></dt><dt id="credits"><span class="yiyi-st" id="yiyi-51"><code class="descname">credits</code></span></dt><dd><p><span class="yiyi-st" id="yiyi-52">当打印这些对象时打印一条类似“Type license() to see the full license text”的信息当调用它们时则以分页的方式一次一个屏幕显示相应的文本。</span></p></dd></dl></div></div></div>