Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
functions.html2634 linesDownload Raw Back to docs
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4  <head>5    <meta charset="utf-8" />6    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="Built-in Functions" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/functions.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.,,,, Built-in Functions,,, A, abs(), aiter(), all(), a..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_functions_087d61cd.png" />15<meta property="og:image:alt" content="The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.,,,, Built-in Functions,,, A, abs(), aiter(), all(), a..." />16<meta name="description" content="The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.,,,, Built-in Functions,,, A, abs(), aiter(), all(), a..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>Built-in Functions &#8212; Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21    22    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23    <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25    <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26    <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27    28    <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29    <script src="../_static/doctools.js?v=9bcbadda"></script>30    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31    <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32    33    <script src="../_static/sidebar.js"></script>34    35    <link rel="search" type="application/opensearchdescription+xml"36          title="Search within Python 3.15.0a6 documentation"37          href="../_static/opensearch.xml"/>38    <link rel="author" title="About these documents" href="../about.html" />39    <link rel="index" title="Index" href="../genindex.html" />40    <link rel="search" title="Search" href="../search.html" />41    <link rel="copyright" title="Copyright" href="../copyright.html" />42    <link rel="next" title="Built-in Constants" href="constants.html" />43    <link rel="prev" title="Introduction" href="intro.html" />44    45      46      <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47      48      <link rel="canonical" href="https://docs.python.org/3/library/functions.html">49      50    51 52    53    <style>54      @media only screen {55        table.full-width-table {56            width: 100%;57        }58      }59    </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61    <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62            <script type="text/javascript" src="../_static/copybutton.js"></script>63            <script type="text/javascript" src="../_static/menu.js"></script>64            <script type="text/javascript" src="../_static/search-focus.js"></script>65            <script type="text/javascript" src="../_static/themetoggle.js"></script> 66            <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67            <meta name="readthedocs-addons-api-version" content="1">68 69  </head>70<body>71<div class="mobile-nav">72    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74    <nav class="nav-content" role="navigation">75        <label for="menuToggler" class="toggler__label">76            <span></span>77        </label>78        <span class="nav-items-wrapper">79            <a href="https://www.python.org/" class="nav-logo">80                <img src="../_static/py.svg" alt="Python logo">81            </a>82            <span class="version_switcher_placeholder"></span>83            <form role="search" class="search" action="../search.html" method="get">84                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85                    <path fill-rule="nonzero" fill="currentColor" 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"></path>86                </svg>87                <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88                <input type="submit" value="Go">89            </form>90        </span>91    </nav>92    <div class="menu-wrapper">93        <nav class="menu" role="navigation" aria-label="main navigation">94            <div class="language_switcher_placeholder"></div>95            96<label class="theme-selector-label">97    Theme98    <select class="theme-selector" oninput="activateTheme(this.value)">99        <option value="auto" selected>Auto</option>100        <option value="light">Light</option>101        <option value="dark">Dark</option>102    </select>103</label>104  <div>105    <h4>Previous topic</h4>106    <p class="topless"><a href="intro.html"107                          title="previous chapter">Introduction</a></p>108  </div>109  <div>110    <h4>Next topic</h4>111    <p class="topless"><a href="constants.html"112                          title="next chapter">Built-in Constants</a></p>113  </div>114  <script>115    document.addEventListener('DOMContentLoaded', () => {116        const title = document.querySelector('meta[property="og:title"]').content;117        const elements = document.querySelectorAll('.improvepage');118        const pageurl = window.location.href.split('?')[0];119        elements.forEach(element => {120            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));121            url.searchParams.set('pagetitle', title);122            url.searchParams.set('pageurl', pageurl);123            url.searchParams.set('pagesource', "library/functions.rst");124            element.href = url.toString();125        });126    });127  </script>128  <div role="note" aria-label="source link">129    <h3>This page</h3>130    <ul class="this-page-menu">131      <li><a href="../bugs.html">Report a bug</a></li>132      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>133      <li>134        <a href="https://github.com/python/cpython/blob/main/Doc/library/functions.rst?plain=1"135            rel="nofollow">Show source136        </a>137      </li>138      139    </ul>140  </div>141        </nav>142    </div>143</div>144 145  146    <div class="related" role="navigation" aria-label="Related">147      <h3>Navigation</h3>148      <ul>149        <li class="right" style="margin-right: 10px">150          <a href="../genindex.html" title="General Index"151             accesskey="I">index</a></li>152        <li class="right" >153          <a href="../py-modindex.html" title="Python Module Index"154             >modules</a> |</li>155        <li class="right" >156          <a href="constants.html" title="Built-in Constants"157             accesskey="N">next</a> |</li>158        <li class="right" >159          <a href="intro.html" title="Introduction"160             accesskey="P">previous</a> |</li>161 162          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>163          <li><a href="https://www.python.org/">Python</a> &#187;</li>164          <li class="switchers">165            <div class="language_switcher_placeholder"></div>166            <div class="version_switcher_placeholder"></div>167          </li>168          <li>169              170          </li>171    <li id="cpython-language-and-version">172      <a href="../index.html">3.15.0a6 Documentation</a> &#187;173    </li>174 175          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">The Python Standard Library</a> &#187;</li>176        <li class="nav-item nav-item-this"><a href="">Built-in Functions</a></li>177                <li class="right">178                    179 180    <div class="inline-search" role="search">181        <form class="inline-search" action="../search.html" method="get">182          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">183          <input type="submit" value="Go">184        </form>185    </div>186                     |187                </li>188            <li class="right">189<label class="theme-selector-label">190    Theme191    <select class="theme-selector" oninput="activateTheme(this.value)">192        <option value="auto" selected>Auto</option>193        <option value="light">Light</option>194        <option value="dark">Dark</option>195    </select>196</label> |</li>197            198      </ul>199    </div>    200 201    <div class="document">202      <div class="documentwrapper">203        <div class="bodywrapper">204          <div class="body" role="main">205            206  <section id="built-in-functions">207<span id="built-in-funcs"></span><h1>Built-in Functions<a class="headerlink" href="#built-in-functions" title="Link to this heading">¶</a></h1>208<p>The Python interpreter has a number of functions and types built into it that209are always available.  They are listed here in alphabetical order.</p>210<table class="docutils align-default">211<thead>212<tr class="row-odd"><th class="head" colspan="4"><p>Built-in Functions</p></th>213</tr>214</thead>215<tbody>216<tr class="row-even"><td><div class="line-block">217<div class="line"><strong>A</strong></div>218<div class="line"><a class="reference internal" href="#abs" title="abs"><code class="xref py py-func docutils literal notranslate"><span class="pre">abs()</span></code></a></div>219<div class="line"><a class="reference internal" href="#aiter" title="aiter"><code class="xref py py-func docutils literal notranslate"><span class="pre">aiter()</span></code></a></div>220<div class="line"><a class="reference internal" href="#all" title="all"><code class="xref py py-func docutils literal notranslate"><span class="pre">all()</span></code></a></div>221<div class="line"><a class="reference internal" href="#anext" title="anext"><code class="xref py py-func docutils literal notranslate"><span class="pre">anext()</span></code></a></div>222<div class="line"><a class="reference internal" href="#any" title="any"><code class="xref py py-func docutils literal notranslate"><span class="pre">any()</span></code></a></div>223<div class="line"><a class="reference internal" href="#ascii" title="ascii"><code class="xref py py-func docutils literal notranslate"><span class="pre">ascii()</span></code></a></div>224<div class="line"><br /></div>225<div class="line"><strong>B</strong></div>226<div class="line"><a class="reference internal" href="#bin" title="bin"><code class="xref py py-func docutils literal notranslate"><span class="pre">bin()</span></code></a></div>227<div class="line"><a class="reference internal" href="#bool" title="bool"><code class="xref py py-func docutils literal notranslate"><span class="pre">bool()</span></code></a></div>228<div class="line"><a class="reference internal" href="#breakpoint" title="breakpoint"><code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code></a></div>229<div class="line"><a class="reference internal" href="#func-bytearray"><code class="docutils literal notranslate"><span class="pre">bytearray()</span></code></a></div>230<div class="line"><a class="reference internal" href="#func-bytes"><code class="docutils literal notranslate"><span class="pre">bytes()</span></code></a></div>231<div class="line"><br /></div>232<div class="line"><strong>C</strong></div>233<div class="line"><a class="reference internal" href="#callable" title="callable"><code class="xref py py-func docutils literal notranslate"><span class="pre">callable()</span></code></a></div>234<div class="line"><a class="reference internal" href="#chr" title="chr"><code class="xref py py-func docutils literal notranslate"><span class="pre">chr()</span></code></a></div>235<div class="line"><a class="reference internal" href="#classmethod" title="classmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">classmethod()</span></code></a></div>236<div class="line"><a class="reference internal" href="#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a></div>237<div class="line"><a class="reference internal" href="#complex" title="complex"><code class="xref py py-func docutils literal notranslate"><span class="pre">complex()</span></code></a></div>238<div class="line"><br /></div>239<div class="line"><strong>D</strong></div>240<div class="line"><a class="reference internal" href="#delattr" title="delattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">delattr()</span></code></a></div>241<div class="line"><a class="reference internal" href="#func-dict"><code class="docutils literal notranslate"><span class="pre">dict()</span></code></a></div>242<div class="line"><a class="reference internal" href="#dir" title="dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">dir()</span></code></a></div>243<div class="line"><a class="reference internal" href="#divmod" title="divmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">divmod()</span></code></a></div>244<div class="line"><br /></div>245</div>246</td>247<td><div class="line-block">248<div class="line"><strong>E</strong></div>249<div class="line"><a class="reference internal" href="#enumerate" title="enumerate"><code class="xref py py-func docutils literal notranslate"><span class="pre">enumerate()</span></code></a></div>250<div class="line"><a class="reference internal" href="#eval" title="eval"><code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code></a></div>251<div class="line"><a class="reference internal" href="#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a></div>252<div class="line"><br /></div>253<div class="line"><strong>F</strong></div>254<div class="line"><a class="reference internal" href="#filter" title="filter"><code class="xref py py-func docutils literal notranslate"><span class="pre">filter()</span></code></a></div>255<div class="line"><a class="reference internal" href="#float" title="float"><code class="xref py py-func docutils literal notranslate"><span class="pre">float()</span></code></a></div>256<div class="line"><a class="reference internal" href="#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a></div>257<div class="line"><a class="reference internal" href="#func-frozenset"><code class="docutils literal notranslate"><span class="pre">frozenset()</span></code></a></div>258<div class="line"><br /></div>259<div class="line"><strong>G</strong></div>260<div class="line"><a class="reference internal" href="#getattr" title="getattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">getattr()</span></code></a></div>261<div class="line"><a class="reference internal" href="#globals" title="globals"><code class="xref py py-func docutils literal notranslate"><span class="pre">globals()</span></code></a></div>262<div class="line"><br /></div>263<div class="line"><strong>H</strong></div>264<div class="line"><a class="reference internal" href="#hasattr" title="hasattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">hasattr()</span></code></a></div>265<div class="line"><a class="reference internal" href="#hash" title="hash"><code class="xref py py-func docutils literal notranslate"><span class="pre">hash()</span></code></a></div>266<div class="line"><a class="reference internal" href="#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a></div>267<div class="line"><a class="reference internal" href="#hex" title="hex"><code class="xref py py-func docutils literal notranslate"><span class="pre">hex()</span></code></a></div>268<div class="line"><br /></div>269<div class="line"><strong>I</strong></div>270<div class="line"><a class="reference internal" href="#id" title="id"><code class="xref py py-func docutils literal notranslate"><span class="pre">id()</span></code></a></div>271<div class="line"><a class="reference internal" href="#input" title="input"><code class="xref py py-func docutils literal notranslate"><span class="pre">input()</span></code></a></div>272<div class="line"><a class="reference internal" href="#int" title="int"><code class="xref py py-func docutils literal notranslate"><span class="pre">int()</span></code></a></div>273<div class="line"><a class="reference internal" href="#isinstance" title="isinstance"><code class="xref py py-func docutils literal notranslate"><span class="pre">isinstance()</span></code></a></div>274<div class="line"><a class="reference internal" href="#issubclass" title="issubclass"><code class="xref py py-func docutils literal notranslate"><span class="pre">issubclass()</span></code></a></div>275<div class="line"><a class="reference internal" href="#iter" title="iter"><code class="xref py py-func docutils literal notranslate"><span class="pre">iter()</span></code></a></div>276</div>277</td>278<td><div class="line-block">279<div class="line"><strong>L</strong></div>280<div class="line"><a class="reference internal" href="#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a></div>281<div class="line"><a class="reference internal" href="#func-list"><code class="docutils literal notranslate"><span class="pre">list()</span></code></a></div>282<div class="line"><a class="reference internal" href="#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a></div>283<div class="line"><br /></div>284<div class="line"><strong>M</strong></div>285<div class="line"><a class="reference internal" href="#map" title="map"><code class="xref py py-func docutils literal notranslate"><span class="pre">map()</span></code></a></div>286<div class="line"><a class="reference internal" href="#max" title="max"><code class="xref py py-func docutils literal notranslate"><span class="pre">max()</span></code></a></div>287<div class="line"><a class="reference internal" href="#func-memoryview"><code class="docutils literal notranslate"><span class="pre">memoryview()</span></code></a></div>288<div class="line"><a class="reference internal" href="#min" title="min"><code class="xref py py-func docutils literal notranslate"><span class="pre">min()</span></code></a></div>289<div class="line"><br /></div>290<div class="line"><strong>N</strong></div>291<div class="line"><a class="reference internal" href="#next" title="next"><code class="xref py py-func docutils literal notranslate"><span class="pre">next()</span></code></a></div>292<div class="line"><br /></div>293<div class="line"><strong>O</strong></div>294<div class="line"><a class="reference internal" href="#object" title="object"><code class="xref py py-func docutils literal notranslate"><span class="pre">object()</span></code></a></div>295<div class="line"><a class="reference internal" href="#oct" title="oct"><code class="xref py py-func docutils literal notranslate"><span class="pre">oct()</span></code></a></div>296<div class="line"><a class="reference internal" href="#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a></div>297<div class="line"><a class="reference internal" href="#ord" title="ord"><code class="xref py py-func docutils literal notranslate"><span class="pre">ord()</span></code></a></div>298<div class="line"><br /></div>299<div class="line"><strong>P</strong></div>300<div class="line"><a class="reference internal" href="#pow" title="pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">pow()</span></code></a></div>301<div class="line"><a class="reference internal" href="#print" title="print"><code class="xref py py-func docutils literal notranslate"><span class="pre">print()</span></code></a></div>302<div class="line"><a class="reference internal" href="#property" title="property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a></div>303<div class="line"><br /></div>304<div class="line"><br /></div>305<div class="line"><br /></div>306<div class="line"><br /></div>307</div>308</td>309<td><div class="line-block">310<div class="line"><strong>R</strong></div>311<div class="line"><a class="reference internal" href="#func-range"><code class="docutils literal notranslate"><span class="pre">range()</span></code></a></div>312<div class="line"><a class="reference internal" href="#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a></div>313<div class="line"><a class="reference internal" href="#reversed" title="reversed"><code class="xref py py-func docutils literal notranslate"><span class="pre">reversed()</span></code></a></div>314<div class="line"><a class="reference internal" href="#round" title="round"><code class="xref py py-func docutils literal notranslate"><span class="pre">round()</span></code></a></div>315<div class="line"><br /></div>316<div class="line"><strong>S</strong></div>317<div class="line"><a class="reference internal" href="#func-set"><code class="docutils literal notranslate"><span class="pre">set()</span></code></a></div>318<div class="line"><a class="reference internal" href="#setattr" title="setattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">setattr()</span></code></a></div>319<div class="line"><a class="reference internal" href="#slice" title="slice"><code class="xref py py-func docutils literal notranslate"><span class="pre">slice()</span></code></a></div>320<div class="line"><a class="reference internal" href="#sorted" title="sorted"><code class="xref py py-func docutils literal notranslate"><span class="pre">sorted()</span></code></a></div>321<div class="line"><a class="reference internal" href="#staticmethod" title="staticmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">staticmethod()</span></code></a></div>322<div class="line"><a class="reference internal" href="#func-str"><code class="docutils literal notranslate"><span class="pre">str()</span></code></a></div>323<div class="line"><a class="reference internal" href="#sum" title="sum"><code class="xref py py-func docutils literal notranslate"><span class="pre">sum()</span></code></a></div>324<div class="line"><a class="reference internal" href="#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a></div>325<div class="line"><br /></div>326<div class="line"><strong>T</strong></div>327<div class="line"><a class="reference internal" href="#func-tuple"><code class="docutils literal notranslate"><span class="pre">tuple()</span></code></a></div>328<div class="line"><a class="reference internal" href="#type" title="type"><code class="xref py py-func docutils literal notranslate"><span class="pre">type()</span></code></a></div>329<div class="line"><br /></div>330<div class="line"><strong>V</strong></div>331<div class="line"><a class="reference internal" href="#vars" title="vars"><code class="xref py py-func docutils literal notranslate"><span class="pre">vars()</span></code></a></div>332<div class="line"><br /></div>333<div class="line"><strong>Z</strong></div>334<div class="line"><a class="reference internal" href="#zip" title="zip"><code class="xref py py-func docutils literal notranslate"><span class="pre">zip()</span></code></a></div>335<div class="line"><br /></div>336<div class="line"><strong>_</strong></div>337<div class="line"><a class="reference internal" href="#import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a></div>338</div>339</td>340</tr>341</tbody>342</table>343<dl class="py function">344<dt class="sig sig-object py" id="abs">345<span class="sig-name descname"><span class="pre">abs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">number</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#abs" title="Link to this definition">¶</a></dt>346<dd><p>Return the absolute value of a number.  The argument may be an347integer, a floating-point number, or an object implementing348<a class="reference internal" href="../reference/datamodel.html#object.__abs__" title="object.__abs__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__abs__()</span></code></a>.349If the argument is a complex number, its magnitude is returned.</p>350</dd></dl>351 352<dl class="py function">353<dt class="sig sig-object py" id="aiter">354<span class="sig-name descname"><span class="pre">aiter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">async_iterable</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#aiter" title="Link to this definition">¶</a></dt>355<dd><p>Return an <a class="reference internal" href="../glossary.html#term-asynchronous-iterator"><span class="xref std std-term">asynchronous iterator</span></a> for an <a class="reference internal" href="../glossary.html#term-asynchronous-iterable"><span class="xref std std-term">asynchronous iterable</span></a>.356Equivalent to calling <code class="docutils literal notranslate"><span class="pre">x.__aiter__()</span></code>.</p>357<p>Note: Unlike <a class="reference internal" href="#iter" title="iter"><code class="xref py py-func docutils literal notranslate"><span class="pre">iter()</span></code></a>, <code class="xref py py-func docutils literal notranslate"><span class="pre">aiter()</span></code> has no 2-argument variant.</p>358<div class="versionadded">359<p><span class="versionmodified added">Added in version 3.10.</span></p>360</div>361</dd></dl>362 363<dl class="py function">364<dt class="sig sig-object py" id="all">365<span class="sig-name descname"><span class="pre">all</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">iterable</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#all" title="Link to this definition">¶</a></dt>366<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if all elements of the <em>iterable</em> are true (or if the iterable367is empty).  Equivalent to:</p>368<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">all</span><span class="p">(</span><span class="n">iterable</span><span class="p">):</span>369    <span class="k">for</span> <span class="n">element</span> <span class="ow">in</span> <span class="n">iterable</span><span class="p">:</span>370        <span class="k">if</span> <span class="ow">not</span> <span class="n">element</span><span class="p">:</span>371            <span class="k">return</span> <span class="kc">False</span>372    <span class="k">return</span> <span class="kc">True</span>373</pre></div>374</div>375</dd></dl>376 377<dl class="py function">378<dt class="sig sig-object py" id="anext">379<em class="property"><span class="pre">awaitable</span> </em><span class="sig-name descname"><span class="pre">anext</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">async_iterator</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#anext" title="Link to this definition">¶</a></dt>380<dt class="sig sig-object py">381<em class="property"><span class="pre">awaitable</span> </em><span class="sig-name descname"><span class="pre">anext</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">async_iterator</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span></dt>382<dd><p>When awaited, return the next item from the given <a class="reference internal" href="../glossary.html#term-asynchronous-iterator"><span class="xref std std-term">asynchronous383iterator</span></a>, or <em>default</em> if given and the iterator is exhausted.</p>384<p>This is the async variant of the <a class="reference internal" href="#next" title="next"><code class="xref py py-func docutils literal notranslate"><span class="pre">next()</span></code></a> builtin, and behaves385similarly.</p>386<p>This calls the <a class="reference internal" href="../reference/datamodel.html#object.__anext__" title="object.__anext__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__anext__()</span></code></a> method of <em>async_iterator</em>,387returning an <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitable</span></a>. Awaiting this returns the next value of the388iterator. If <em>default</em> is given, it is returned if the iterator is exhausted,389otherwise <a class="reference internal" href="exceptions.html#StopAsyncIteration" title="StopAsyncIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopAsyncIteration</span></code></a> is raised.</p>390<div class="versionadded">391<p><span class="versionmodified added">Added in version 3.10.</span></p>392</div>393</dd></dl>394 395<dl class="py function">396<dt class="sig sig-object py" id="any">397<span class="sig-name descname"><span class="pre">any</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">iterable</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#any" title="Link to this definition">¶</a></dt>398<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if any element of the <em>iterable</em> is true.  If the iterable399is empty, return <code class="docutils literal notranslate"><span class="pre">False</span></code>.  Equivalent to:</p>400<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">any</span><span class="p">(</span><span class="n">iterable</span><span class="p">):</span>401    <span class="k">for</span> <span class="n">element</span> <span class="ow">in</span> <span class="n">iterable</span><span class="p">:</span>402        <span class="k">if</span> <span class="n">element</span><span class="p">:</span>403            <span class="k">return</span> <span class="kc">True</span>404    <span class="k">return</span> <span class="kc">False</span>405</pre></div>406</div>407</dd></dl>408 409<dl class="py function">410<dt class="sig sig-object py" id="ascii">411<span class="sig-name descname"><span class="pre">ascii</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#ascii" title="Link to this definition">¶</a></dt>412<dd><p>As <a class="reference internal" href="#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a>, return a string containing a printable representation of an413object, but escape the non-ASCII characters in the string returned by414<code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code> using <code class="docutils literal notranslate"><span class="pre">\x</span></code>, <code class="docutils literal notranslate"><span class="pre">\u</span></code>, or <code class="docutils literal notranslate"><span class="pre">\U</span></code> escapes.  This generates a string415similar to that returned by <code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code> in Python 2.</p>416</dd></dl>417 418<dl class="py function">419<dt class="sig sig-object py" id="bin">420<span class="sig-name descname"><span class="pre">bin</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">integer</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bin" title="Link to this definition">¶</a></dt>421<dd><p>Convert an integer number to a binary string prefixed with “0b”. The result422is a valid Python expression. If <em>integer</em> is not a Python <a class="reference internal" href="#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> object, it423has to define an <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> method that returns an integer. Some424examples:</p>425<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">bin</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>426<span class="go">&#39;0b11&#39;</span>427<span class="gp">&gt;&gt;&gt; </span><span class="nb">bin</span><span class="p">(</span><span class="o">-</span><span class="mi">10</span><span class="p">)</span>428<span class="go">&#39;-0b1010&#39;</span>429</pre></div>430</div>431<p>If the prefix “0b” is desired or not, you can use either of the following ways.</p>432<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">format</span><span class="p">(</span><span class="mi">14</span><span class="p">,</span> <span class="s1">&#39;#b&#39;</span><span class="p">),</span> <span class="nb">format</span><span class="p">(</span><span class="mi">14</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">)</span>433<span class="go">(&#39;0b1110&#39;, &#39;1110&#39;)</span>434<span class="gp">&gt;&gt;&gt; </span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="mi">14</span><span class="si">:</span><span class="s1">#b</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span> <span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="mi">14</span><span class="si">:</span><span class="s1">b</span><span class="si">}</span><span class="s1">&#39;</span>435<span class="go">(&#39;0b1110&#39;, &#39;1110&#39;)</span>436</pre></div>437</div>438<p>See also <a class="reference internal" href="enum.html#enum.bin" title="enum.bin"><code class="xref py py-func docutils literal notranslate"><span class="pre">enum.bin()</span></code></a> to represent negative values as twos-complement.</p>439<p>See also <a class="reference internal" href="#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a> for more information.</p>440</dd></dl>441 442<dl class="py class">443<dt class="sig sig-object py" id="bool">444<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">bool</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#bool" title="Link to this definition">¶</a></dt>445<dd><p>Return a Boolean value, i.e. one of <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code>.  The argument446is converted using the standard <a class="reference internal" href="stdtypes.html#truth"><span class="std std-ref">truth testing procedure</span></a>.447If the argument is false448or omitted, this returns <code class="docutils literal notranslate"><span class="pre">False</span></code>; otherwise, it returns <code class="docutils literal notranslate"><span class="pre">True</span></code>.  The449<code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code> class is a subclass of <a class="reference internal" href="#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> (see <a class="reference internal" href="stdtypes.html#typesnumeric"><span class="std std-ref">Numeric Types — int, float, complex</span></a>).450It cannot be subclassed further.  Its only instances are <code class="docutils literal notranslate"><span class="pre">False</span></code> and451<code class="docutils literal notranslate"><span class="pre">True</span></code> (see <a class="reference internal" href="stdtypes.html#typebool"><span class="std std-ref">Boolean Type - bool</span></a>).</p>452<div class="versionchanged" id="index-0">453<p><span class="versionmodified changed">Changed in version 3.7: </span>The parameter is now positional-only.</p>454</div>455</dd></dl>456 457<dl class="py function">458<dt class="sig sig-object py" id="breakpoint">459<span class="sig-name descname"><span class="pre">breakpoint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kws</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#breakpoint" title="Link to this definition">¶</a></dt>460<dd><p>This function drops you into the debugger at the call site.  Specifically,461it calls <a class="reference internal" href="sys.html#sys.breakpointhook" title="sys.breakpointhook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.breakpointhook()</span></code></a>, passing <code class="docutils literal notranslate"><span class="pre">args</span></code> and <code class="docutils literal notranslate"><span class="pre">kws</span></code> straight462through.  By default, <code class="docutils literal notranslate"><span class="pre">sys.breakpointhook()</span></code> calls463<a class="reference internal" href="pdb.html#pdb.set_trace" title="pdb.set_trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">pdb.set_trace()</span></code></a> expecting no arguments.  In this case, it is464purely a convenience function so you don’t have to explicitly import465<a class="reference internal" href="pdb.html#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> or type as much code to enter the debugger.  However,466<code class="xref py py-func docutils literal notranslate"><span class="pre">sys.breakpointhook()</span></code> can be set to some other function and467<code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code> will automatically call that, allowing you to drop into468the debugger of choice.469If <code class="xref py py-func docutils literal notranslate"><span class="pre">sys.breakpointhook()</span></code> is not accessible, this function will470raise <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>.</p>471<p>By default, the behavior of <code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code> can be changed with472the <span class="target" id="index-1"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONBREAKPOINT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONBREAKPOINT</span></code></a> environment variable.473See <a class="reference internal" href="sys.html#sys.breakpointhook" title="sys.breakpointhook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.breakpointhook()</span></code></a> for usage details.</p>474<p>Note that this is not guaranteed if <a class="reference internal" href="sys.html#sys.breakpointhook" title="sys.breakpointhook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.breakpointhook()</span></code></a>475has been replaced.</p>476<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">builtins.breakpoint</span></code> with argument <code class="docutils literal notranslate"><span class="pre">breakpointhook</span></code>.</p>477<div class="versionadded">478<p><span class="versionmodified added">Added in version 3.7.</span></p>479</div>480</dd></dl>481 482<dl class="py class" id="func-bytearray">483<dt class="sig sig-object py">484<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">bytearray</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">b''</span></span></em><span class="sig-paren">)</span></dt>485<dt class="sig sig-object py">486<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">bytearray</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">errors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'strict'</span></span></em><span class="sig-paren">)</span></dt>487<dd><p>Return a new array of bytes.  The <code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code> class is a mutable488sequence of integers in the range 0 &lt;= x &lt; 256.  It has most of the usual489methods of mutable sequences, described in <a class="reference internal" href="stdtypes.html#typesseq-mutable"><span class="std std-ref">Mutable Sequence Types</span></a>, as well490as most methods that the <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> type has, see <a class="reference internal" href="stdtypes.html#bytes-methods"><span class="std std-ref">Bytes and Bytearray Operations</span></a>.</p>491<p>The optional <em>source</em> parameter can be used to initialize the array in a few492different ways:</p>493<ul class="simple">494<li><p>If it is a <em>string</em>, you must also give the <em>encoding</em> (and optionally,495<em>errors</em>) parameters; <a class="reference internal" href="stdtypes.html#bytearray" title="bytearray"><code class="xref py py-func docutils literal notranslate"><span class="pre">bytearray()</span></code></a> then converts the string to496bytes using <a class="reference internal" href="stdtypes.html#str.encode" title="str.encode"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.encode()</span></code></a>.</p></li>497<li><p>If it is an <em>integer</em>, the array will have that size and will be498initialized with null bytes.</p></li>499<li><p>If it is an object conforming to the <a class="reference internal" href="../c-api/buffer.html#bufferobjects"><span class="std std-ref">buffer interface</span></a>,500a read-only buffer of the object will be used to initialize the bytes array.</p></li>501<li><p>If it is an <em>iterable</em>, it must be an iterable of integers in the range502<code class="docutils literal notranslate"><span class="pre">0</span> <span class="pre">&lt;=</span> <span class="pre">x</span> <span class="pre">&lt;</span> <span class="pre">256</span></code>, which are used as the initial contents of the array.</p></li>503</ul>504<p>Without an argument, an array of size 0 is created.</p>505<p>See also <a class="reference internal" href="stdtypes.html#binaryseq"><span class="std std-ref">Binary Sequence Types — bytes, bytearray, memoryview</span></a> and <a class="reference internal" href="stdtypes.html#typebytearray"><span class="std std-ref">Bytearray Objects</span></a>.</p>506</dd></dl>507 508<dl class="py class" id="func-bytes">509<dt class="sig sig-object py">510<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">bytes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">b''</span></span></em><span class="sig-paren">)</span></dt>511<dt class="sig sig-object py">512<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">bytes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">errors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'strict'</span></span></em><span class="sig-paren">)</span></dt>513<dd><p>Return a new “bytes” object which is an immutable sequence of integers in514the range <code class="docutils literal notranslate"><span class="pre">0</span> <span class="pre">&lt;=</span> <span class="pre">x</span> <span class="pre">&lt;</span> <span class="pre">256</span></code>.  <code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code> is an immutable version of515<a class="reference internal" href="stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> – it has the same non-mutating methods and the same516indexing and slicing behavior.</p>517<p>Accordingly, constructor arguments are interpreted as for <a class="reference internal" href="stdtypes.html#bytearray" title="bytearray"><code class="xref py py-func docutils literal notranslate"><span class="pre">bytearray()</span></code></a>.</p>518<p>Bytes objects can also be created with literals, see <a class="reference internal" href="../reference/lexical_analysis.html#strings"><span class="std std-ref">String and Bytes literals</span></a>.</p>519<p>See also <a class="reference internal" href="stdtypes.html#binaryseq"><span class="std std-ref">Binary Sequence Types — bytes, bytearray, memoryview</span></a>, <a class="reference internal" href="stdtypes.html#typebytes"><span class="std std-ref">Bytes Objects</span></a>, and <a class="reference internal" href="stdtypes.html#bytes-methods"><span class="std std-ref">Bytes and Bytearray Operations</span></a>.</p>520</dd></dl>521 522<dl class="py function">523<dt class="sig sig-object py" id="callable">524<span class="sig-name descname"><span class="pre">callable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#callable" title="Link to this definition">¶</a></dt>525<dd><p>Return <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a> if the <em>object</em> argument appears callable,526<a class="reference internal" href="constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a> if not.  If this returns <code class="docutils literal notranslate"><span class="pre">True</span></code>, it is still possible that a527call fails, but if it is <code class="docutils literal notranslate"><span class="pre">False</span></code>, calling <em>object</em> will never succeed.528Note that classes are callable (calling a class returns a new instance);529instances are callable if their class has a <a class="reference internal" href="../reference/datamodel.html#object.__call__" title="object.__call__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__call__()</span></code></a> method.</p>530<div class="versionadded">531<p><span class="versionmodified added">Added in version 3.2: </span>This function was first removed in Python 3.0 and then brought back532in Python 3.2.</p>533</div>534</dd></dl>535 536<dl class="py function">537<dt class="sig sig-object py" id="chr">538<span class="sig-name descname"><span class="pre">chr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">codepoint</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#chr" title="Link to this definition">¶</a></dt>539<dd><p>Return the string representing a character with the specified Unicode code point.540For example, <code class="docutils literal notranslate"><span class="pre">chr(97)</span></code> returns the string <code class="docutils literal notranslate"><span class="pre">'a'</span></code>, while541<code class="docutils literal notranslate"><span class="pre">chr(8364)</span></code> returns the string <code class="docutils literal notranslate"><span class="pre">'€'</span></code>. This is the inverse of <a class="reference internal" href="#ord" title="ord"><code class="xref py py-func docutils literal notranslate"><span class="pre">ord()</span></code></a>.</p>542<p>The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in543base 16).  <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> will be raised if it is outside that range.</p>544</dd></dl>545 546<dl class="py function">547<dt class="sig sig-object py" id="classmethod">548<span class="sig-prename descclassname"><span class="pre">&#64;</span></span><span class="sig-name descname"><span class="pre">classmethod</span></span><a class="headerlink" href="#classmethod" title="Link to this definition">¶</a></dt>549<dd><p>Transform a method into a class method.</p>550<p>A class method receives the class as an implicit first argument, just like an551instance method receives the instance. To declare a class method, use this552idiom:</p>553<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span><span class="w"> </span><span class="nc">C</span><span class="p">:</span>554    <span class="nd">@classmethod</span>555    <span class="k">def</span><span class="w"> </span><span class="nf">f</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="p">):</span> <span class="o">...</span>556</pre></div>557</div>558<p>The <code class="docutils literal notranslate"><span class="pre">&#64;classmethod</span></code> form is a function <a class="reference internal" href="../glossary.html#term-decorator"><span class="xref std std-term">decorator</span></a> – see559<a class="reference internal" href="../reference/compound_stmts.html#function"><span class="std std-ref">Function definitions</span></a> for details.</p>560<p>A class method can be called either on the class (such as <code class="docutils literal notranslate"><span class="pre">C.f()</span></code>) or on an instance (such561as <code class="docutils literal notranslate"><span class="pre">C().f()</span></code>).  The instance is ignored except for its class. If a class562method is called for a derived class, the derived class object is passed as the563implied first argument.</p>564<p>Class methods are different than C++ or Java static methods. If you want those,565see <a class="reference internal" href="#staticmethod" title="staticmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">staticmethod()</span></code></a> in this section.566For more information on class methods, see <a class="reference internal" href="../reference/datamodel.html#types"><span class="std std-ref">The standard type hierarchy</span></a>.</p>567<div class="versionchanged">568<p><span class="versionmodified changed">Changed in version 3.9: </span>Class methods can now wrap other <a class="reference internal" href="../glossary.html#term-descriptor"><span class="xref std std-term">descriptors</span></a> such as569<a class="reference internal" href="#property" title="property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a>.</p>570</div>571<div class="versionchanged">572<p><span class="versionmodified changed">Changed in version 3.10: </span>Class methods now inherit the method attributes573(<a class="reference internal" href="../reference/datamodel.html#function.__module__" title="function.__module__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__module__</span></code></a>, <a class="reference internal" href="../reference/datamodel.html#function.__name__" title="function.__name__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__name__</span></code></a>,574<a class="reference internal" href="../reference/datamodel.html#function.__qualname__" title="function.__qualname__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__qualname__</span></code></a>, <a class="reference internal" href="../reference/datamodel.html#function.__doc__" title="function.__doc__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__doc__</span></code></a> and575<a class="reference internal" href="../reference/datamodel.html#function.__annotations__" title="function.__annotations__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__annotations__</span></code></a>) and have a new <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code>576attribute.</p>577</div>578<div class="deprecated-removed">579<p><span class="versionmodified removed">Deprecated since version 3.11, removed in version 3.13: </span>Class methods can no longer wrap other <a class="reference internal" href="../glossary.html#term-descriptor"><span class="xref std std-term">descriptors</span></a> such as580<a class="reference internal" href="#property" title="property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a>.</p>581</div>582</dd></dl>583 584<dl class="py function">585<dt class="sig sig-object py" id="compile">586<span class="sig-name descname"><span class="pre">compile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dont_inherit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">optimize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">module</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#compile" title="Link to this definition">¶</a></dt>587<dd><p>Compile the <em>source</em> into a code or AST object.  Code objects can be executed588by <a class="reference internal" href="#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a> or <a class="reference internal" href="#eval" title="eval"><code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code></a>.  <em>source</em> can either be a normal string, a589byte string, or an AST object.  Refer to the <a class="reference internal" href="ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a> module documentation590for information on how to work with AST objects.</p>591<p>The <em>filename</em> argument should give the file from which the code was read;592pass some recognizable value if it wasn’t read from a file (<code class="docutils literal notranslate"><span class="pre">'&lt;string&gt;'</span></code> is593commonly used).</p>594<p>The <em>mode</em> argument specifies what kind of code must be compiled; it can be595<code class="docutils literal notranslate"><span class="pre">'exec'</span></code> if <em>source</em> consists of a sequence of statements, <code class="docutils literal notranslate"><span class="pre">'eval'</span></code> if it596consists of a single expression, or <code class="docutils literal notranslate"><span class="pre">'single'</span></code> if it consists of a single597interactive statement (in the latter case, expression statements that598evaluate to something other than <code class="docutils literal notranslate"><span class="pre">None</span></code> will be printed).</p>599<p>The optional arguments <em>flags</em> and <em>dont_inherit</em> control which600<a class="reference internal" href="ast.html#ast-compiler-flags"><span class="std std-ref">compiler options</span></a> should be activated601and which <a class="reference internal" href="../reference/simple_stmts.html#future"><span class="std std-ref">future features</span></a> should be allowed. If neither602is present (or both are zero) the code is compiled with the same flags that603affect the code that is calling <code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code>. If the <em>flags</em>604argument is given and <em>dont_inherit</em> is not (or is zero) then the compiler605options and the future statements specified by the <em>flags</em> argument are used606in addition to those that would be used anyway. If <em>dont_inherit</em> is a607non-zero integer then the <em>flags</em> argument is it – the flags (future608features and compiler options) in the surrounding code are ignored.</p>609<p>Compiler options and future statements are specified by bits which can be610bitwise ORed together to specify multiple options. The bitfield required to611specify a given future feature can be found as the612<a class="reference internal" href="__future__.html#future__._Feature.compiler_flag" title="__future__._Feature.compiler_flag"><code class="xref py py-attr docutils literal notranslate"><span class="pre">compiler_flag</span></code></a> attribute on the613<a class="reference internal" href="__future__.html#future__._Feature" title="__future__._Feature"><code class="xref py py-class docutils literal notranslate"><span class="pre">_Feature</span></code></a> instance in the <a class="reference internal" href="__future__.html#module-__future__" title="__future__: Future statement definitions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">__future__</span></code></a> module.614<a class="reference internal" href="ast.html#ast-compiler-flags"><span class="std std-ref">Compiler flags</span></a> can be found in <a class="reference internal" href="ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a>615module, with <code class="docutils literal notranslate"><span class="pre">PyCF_</span></code> prefix.</p>616<p>The argument <em>optimize</em> specifies the optimization level of the compiler; the617default value of <code class="docutils literal notranslate"><span class="pre">-1</span></code> selects the optimization level of the interpreter as618given by <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> options.  Explicit levels are <code class="docutils literal notranslate"><span class="pre">0</span></code> (no optimization;619<code class="docutils literal notranslate"><span class="pre">__debug__</span></code> is true), <code class="docutils literal notranslate"><span class="pre">1</span></code> (asserts are removed, <code class="docutils literal notranslate"><span class="pre">__debug__</span></code> is false)620or <code class="docutils literal notranslate"><span class="pre">2</span></code> (docstrings are removed too).</p>621<p>The optional argument <em>module</em> specifies the module name.622It is needed to unambiguous <a class="reference internal" href="warnings.html#warning-filter"><span class="std std-ref">filter</span></a> syntax warnings623by module name.</p>624<p>This function raises <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> or <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> if the compiled625source is invalid.</p>626<p>If you want to parse Python code into its AST representation, see627<a class="reference internal" href="ast.html#ast.parse" title="ast.parse"><code class="xref py py-func docutils literal notranslate"><span class="pre">ast.parse()</span></code></a>.</p>628<p class="audit-hook"><p>Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">compile</span></code> with arguments629<code class="docutils literal notranslate"><span class="pre">source</span></code> and <code class="docutils literal notranslate"><span class="pre">filename</span></code>. This event may also be raised by implicit630compilation.</p>631</p>632<div class="admonition note">633<p class="admonition-title">Note</p>634<p>When compiling a string with multi-line code in <code class="docutils literal notranslate"><span class="pre">'single'</span></code> or635<code class="docutils literal notranslate"><span class="pre">'eval'</span></code> mode, input must be terminated by at least one newline636character.  This is to facilitate detection of incomplete and complete637statements in the <a class="reference internal" href="code.html#module-code" title="code: Facilities to implement read-eval-print loops."><code class="xref py py-mod docutils literal notranslate"><span class="pre">code</span></code></a> module.</p>638</div>639<div class="admonition warning">640<p class="admonition-title">Warning</p>641<p>It is possible to crash the Python interpreter with a642sufficiently large/complex string when compiling to an AST643object due to stack depth limitations in Python’s AST compiler.</p>644</div>645<div class="versionchanged">646<p><span class="versionmodified changed">Changed in version 3.2: </span>Allowed use of Windows and Mac newlines.  Also, input in <code class="docutils literal notranslate"><span class="pre">'exec'</span></code> mode647does not have to end in a newline anymore.  Added the <em>optimize</em> parameter.</p>648</div>649<div class="versionchanged">650<p><span class="versionmodified changed">Changed in version 3.5: </span>Previously, <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> was raised when null bytes were encountered651in <em>source</em>.</p>652</div>653<div class="versionadded">654<p><span class="versionmodified added">Added in version 3.8: </span><code class="docutils literal notranslate"><span class="pre">ast.PyCF_ALLOW_TOP_LEVEL_AWAIT</span></code> can now be passed in flags to enable655support for top-level <code class="docutils literal notranslate"><span class="pre">await</span></code>, <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">for</span></code>, and <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">with</span></code>.</p>656</div>657<div class="versionadded">658<p><span class="versionmodified added">Added in version 3.15: </span>Added the <em>module</em> parameter.</p>659</div>660</dd></dl>661 662<dl class="py class">663<dt class="sig sig-object py" id="complex">664<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">complex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">number</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#complex" title="Link to this definition">¶</a></dt>665<dt class="sig sig-object py">666<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">complex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span></dt>667<dt class="sig sig-object py">668<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">complex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">real</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">imag</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span></dt>669<dd><p>Convert a single string or number to a complex number, or create a670complex number from real and imaginary parts.</p>671<p>Examples:</p>672<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">complex</span><span class="p">(</span><span class="s1">&#39;+1.23&#39;</span><span class="p">)</span>673<span class="go">(1.23+0j)</span>674<span class="gp">&gt;&gt;&gt; </span><span class="nb">complex</span><span class="p">(</span><span class="s1">&#39;-4.5j&#39;</span><span class="p">)</span>675<span class="go">-4.5j</span>676<span class="gp">&gt;&gt;&gt; </span><span class="nb">complex</span><span class="p">(</span><span class="s1">&#39;-1.23+4.5j&#39;</span><span class="p">)</span>677<span class="go">(-1.23+4.5j)</span>678<span class="gp">&gt;&gt;&gt; </span><span class="nb">complex</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\t</span><span class="s1">( -1.23+4.5J )</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>679<span class="go">(-1.23+4.5j)</span>680<span class="gp">&gt;&gt;&gt; </span><span class="nb">complex</span><span class="p">(</span><span class="s1">&#39;-Infinity+NaNj&#39;</span><span class="p">)</span>681<span class="go">(-inf+nanj)</span>682<span class="gp">&gt;&gt;&gt; </span><span class="nb">complex</span><span class="p">(</span><span class="mf">1.23</span><span class="p">)</span>683<span class="go">(1.23+0j)</span>684<span class="gp">&gt;&gt;&gt; </span><span class="nb">complex</span><span class="p">(</span><span class="n">imag</span><span class="o">=-</span><span class="mf">4.5</span><span class="p">)</span>685<span class="go">-4.5j</span>686<span class="gp">&gt;&gt;&gt; </span><span class="nb">complex</span><span class="p">(</span><span class="o">-</span><span class="mf">1.23</span><span class="p">,</span> <span class="mf">4.5</span><span class="p">)</span>687<span class="go">(-1.23+4.5j)</span>688</pre></div>689</div>690<p>If the argument is a string, it must contain either a real part (in the691same format as for <a class="reference internal" href="#float" title="float"><code class="xref py py-func docutils literal notranslate"><span class="pre">float()</span></code></a>) or an imaginary part (in the same692format but with a <code class="docutils literal notranslate"><span class="pre">'j'</span></code> or <code class="docutils literal notranslate"><span class="pre">'J'</span></code> suffix), or both real and imaginary693parts (the sign of the imaginary part is mandatory in this case).694The string can optionally be surrounded by whitespaces and the round695parentheses <code class="docutils literal notranslate"><span class="pre">'('</span></code> and <code class="docutils literal notranslate"><span class="pre">')'</span></code>, which are ignored.696The string must not contain whitespace between <code class="docutils literal notranslate"><span class="pre">'+'</span></code>, <code class="docutils literal notranslate"><span class="pre">'-'</span></code>, the697<code class="docutils literal notranslate"><span class="pre">'j'</span></code> or <code class="docutils literal notranslate"><span class="pre">'J'</span></code> suffix, and the decimal number.698For example, <code class="docutils literal notranslate"><span class="pre">complex('1+2j')</span></code> is fine, but <code class="docutils literal notranslate"><span class="pre">complex('1</span> <span class="pre">+</span> <span class="pre">2j')</span></code> raises699<a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>.700More precisely, the input must conform to the <a class="reference internal" href="#grammar-token-float-complexvalue"><code class="xref std std-token docutils literal notranslate"><span class="pre">complexvalue</span></code></a>701production rule in the following grammar, after parentheses and leading and702trailing whitespace characters are removed:</p>703<pre class="highlight">704<strong id="grammar-token-float-complexvalue">complexvalue</strong>: <a class="reference internal" href="#grammar-token-float-floatvalue"><code class="xref docutils literal notranslate"><span class="pre">floatvalue</span></code></a> |705              <a class="reference internal" href="#grammar-token-float-floatvalue"><code class="xref docutils literal notranslate"><span class="pre">floatvalue</span></code></a> (<span class="sx">&quot;j&quot;</span> | <span class="sx">&quot;J&quot;</span>) |706              <a class="reference internal" href="#grammar-token-float-floatvalue"><code class="xref docutils literal notranslate"><span class="pre">floatvalue</span></code></a> <a class="reference internal" href="#grammar-token-float-sign"><code class="xref docutils literal notranslate"><span class="pre">sign</span></code></a> <a class="reference internal" href="#grammar-token-float-absfloatvalue"><code class="xref docutils literal notranslate"><span class="pre">absfloatvalue</span></code></a> (<span class="sx">&quot;j&quot;</span> | <span class="sx">&quot;J&quot;</span>)707</pre>708<p>If the argument is a number, the constructor serves as a numeric709conversion like <a class="reference internal" href="#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> and <a class="reference internal" href="#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>.710For a general Python object <code class="docutils literal notranslate"><span class="pre">x</span></code>, <code class="docutils literal notranslate"><span class="pre">complex(x)</span></code> delegates to711<code class="docutils literal notranslate"><span class="pre">x.__complex__()</span></code>.712If <a class="reference internal" href="../reference/datamodel.html#object.__complex__" title="object.__complex__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__complex__()</span></code></a> is not defined then it falls back713to <a class="reference internal" href="../reference/datamodel.html#object.__float__" title="object.__float__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__float__()</span></code></a>.714If <code class="xref py py-meth docutils literal notranslate"><span class="pre">__float__()</span></code> is not defined then it falls back715to <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a>.</p>716<p>If two arguments are provided or keyword arguments are used, each argument717may be any numeric type (including complex).718If both arguments are real numbers, return a complex number with the real719component <em>real</em> and the imaginary component <em>imag</em>.720If both arguments are complex numbers, return a complex number with the real721component <code class="docutils literal notranslate"><span class="pre">real.real-imag.imag</span></code> and the imaginary component722<code class="docutils literal notranslate"><span class="pre">real.imag+imag.real</span></code>.723If one of arguments is a real number, only its real component is used in724the above expressions.</p>725<p>See also <a class="reference internal" href="stdtypes.html#complex.from_number" title="complex.from_number"><code class="xref py py-meth docutils literal notranslate"><span class="pre">complex.from_number()</span></code></a> which only accepts a single numeric argument.</p>726<p>If all arguments are omitted, returns <code class="docutils literal notranslate"><span class="pre">0j</span></code>.</p>727<p>The complex type is described in <a class="reference internal" href="stdtypes.html#typesnumeric"><span class="std std-ref">Numeric Types — int, float, complex</span></a>.</p>728<div class="versionchanged">729<p><span class="versionmodified changed">Changed in version 3.6: </span>Grouping digits with underscores as in code literals is allowed.</p>730</div>731<div class="versionchanged">732<p><span class="versionmodified changed">Changed in version 3.8: </span>Falls back to <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> if <a class="reference internal" href="../reference/datamodel.html#object.__complex__" title="object.__complex__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__complex__()</span></code></a> and733<a class="reference internal" href="../reference/datamodel.html#object.__float__" title="object.__float__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__float__()</span></code></a> are not defined.</p>734</div>735<div class="deprecated">736<p><span class="versionmodified deprecated">Deprecated since version 3.14: </span>Passing a complex number as the <em>real</em> or <em>imag</em> argument is now737deprecated; it should only be passed as a single positional argument.</p>738</div>739</dd></dl>740 741<dl class="py function">742<dt class="sig sig-object py" id="delattr">743<span class="sig-name descname"><span class="pre">delattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#delattr" title="Link to this definition">¶</a></dt>744<dd><p>This is a relative of <a class="reference internal" href="#setattr" title="setattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">setattr()</span></code></a>.  The arguments are an object and a745string.  The string must be the name of one of the object’s attributes.  The746function deletes the named attribute, provided the object allows it.  For747example, <code class="docutils literal notranslate"><span class="pre">delattr(x,</span> <span class="pre">'foobar')</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">del</span> <span class="pre">x.foobar</span></code>.748<em>name</em> need not be a Python identifier (see <code class="xref py py-func docutils literal notranslate"><span class="pre">setattr()</span></code>).</p>749</dd></dl>750 751<dl class="py class" id="func-dict">752<dt class="sig sig-object py">753<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">dict</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span></dt>754<dt class="sig sig-object py">755<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">dict</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mapping</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span></dt>756<dt class="sig sig-object py">757<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">dict</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">iterable</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span></dt>758<dd><p>Create a new dictionary.  The <code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code> object is the dictionary class.759See <code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code> and <a class="reference internal" href="stdtypes.html#typesmapping"><span class="std std-ref">Mapping types — dict, frozendict</span></a> for documentation about this class.</p>760<p>For other containers see the built-in <a class="reference internal" href="stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>, <a class="reference internal" href="stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>, and761<a class="reference internal" href="stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a> classes, as well as the <a class="reference internal" href="collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> module.</p>762</dd></dl>763 764<dl class="py function">765<dt class="sig sig-object py" id="dir">766<span class="sig-name descname"><span class="pre">dir</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#dir" title="Link to this definition">¶</a></dt>767<dt class="sig sig-object py">768<span class="sig-name descname"><span class="pre">dir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span></dt>769<dd><p>Without arguments, return the list of names in the current local scope.  With an770argument, attempt to return a list of valid attributes for that object.</p>771<p>If the object has a method named <a class="reference internal" href="../reference/datamodel.html#object.__dir__" title="object.__dir__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__dir__()</span></code></a>,772this method will be called and773must return the list of attributes. This allows objects that implement a custom774<a class="reference internal" href="../reference/datamodel.html#object.__getattr__" title="object.__getattr__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__getattr__()</span></code></a> or <a class="reference internal" href="../reference/datamodel.html#object.__getattribute__" title="object.__getattribute__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__getattribute__()</span></code></a> function775to customize the way776<code class="xref py py-func docutils literal notranslate"><span class="pre">dir()</span></code> reports their attributes.</p>777<p>If the object does not provide <a class="reference internal" href="../reference/datamodel.html#object.__dir__" title="object.__dir__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__dir__()</span></code></a>,778the function tries its best to gather information from the object’s779<a class="reference internal" href="../reference/datamodel.html#object.__dict__" title="object.__dict__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__dict__</span></code></a> attribute, if defined, and780from its type object.  The resulting list is not necessarily complete and may781be inaccurate when the object has a custom <a class="reference internal" href="../reference/datamodel.html#object.__getattr__" title="object.__getattr__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__getattr__()</span></code></a>.</p>782<p>The default <code class="xref py py-func docutils literal notranslate"><span class="pre">dir()</span></code> mechanism behaves differently with different types of783objects, as it attempts to produce the most relevant, rather than complete,784information:</p>785<ul class="simple">786<li><p>If the object is a module object, the list contains the names of the module’s787attributes.</p></li>788<li><p>If the object is a type or class object, the list contains the names of its789attributes, and recursively of the attributes of its bases.</p></li>790<li><p>Otherwise, the list contains the object’s attributes’ names, the names of its791class’s attributes, and recursively of the attributes of its class’s base792classes.</p></li>793</ul>794<p>The resulting list is sorted alphabetically.  For example:</p>795<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span><span class="w"> </span><span class="nn">struct</span>796<span class="gp">&gt;&gt;&gt; </span><span class="nb">dir</span><span class="p">()</span>   <span class="c1"># show the names in the module namespace</span>797<span class="go">[&#39;__builtins__&#39;, &#39;__name__&#39;, &#39;struct&#39;]</span>798<span class="gp">&gt;&gt;&gt; </span><span class="nb">dir</span><span class="p">(</span><span class="n">struct</span><span class="p">)</span>   <span class="c1"># show the names in the struct module</span>799<span class="go">[&#39;Struct&#39;, &#39;__all__&#39;, &#39;__builtins__&#39;, &#39;__doc__&#39;, &#39;__file__&#39;,</span>800<span class="go"> &#39;__initializing__&#39;, &#39;__loader__&#39;, &#39;__name__&#39;, &#39;__package__&#39;,</span>801<span class="go"> &#39;_clearcache&#39;, &#39;calcsize&#39;, &#39;error&#39;, &#39;pack&#39;, &#39;pack_into&#39;,</span>802<span class="go"> &#39;unpack&#39;, &#39;unpack_from&#39;]</span>803<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span><span class="w"> </span><span class="nc">Shape</span><span class="p">:</span>804<span class="gp">... </span>    <span class="k">def</span><span class="w"> </span><span class="fm">__dir__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>805<span class="gp">... </span>        <span class="k">return</span> <span class="p">[</span><span class="s1">&#39;area&#39;</span><span class="p">,</span> <span class="s1">&#39;perimeter&#39;</span><span class="p">,</span> <span class="s1">&#39;location&#39;</span><span class="p">]</span>806<span class="gp">...</span>807<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">Shape</span><span class="p">()</span>808<span class="gp">&gt;&gt;&gt; </span><span class="nb">dir</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>809<span class="go">[&#39;area&#39;, &#39;location&#39;, &#39;perimeter&#39;]</span>810</pre></div>811</div>812<div class="admonition note">813<p class="admonition-title">Note</p>814<p>Because <code class="xref py py-func docutils literal notranslate"><span class="pre">dir()</span></code> is supplied primarily as a convenience for use at an815interactive prompt, it tries to supply an interesting set of names more816than it tries to supply a rigorously or consistently defined set of names,817and its detailed behavior may change across releases.  For example,818metaclass attributes are not in the result list when the argument is a819class.</p>820</div>821</dd></dl>822 823<dl class="py function">824<dt class="sig sig-object py" id="divmod">825<span class="sig-name descname"><span class="pre">divmod</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#divmod" title="Link to this definition">¶</a></dt>826<dd><p>Take two (non-complex) numbers as arguments and return a pair of numbers827consisting of their quotient and remainder when using integer division.  With828mixed operand types, the rules for binary arithmetic operators apply.  For829integers, the result is the same as <code class="docutils literal notranslate"><span class="pre">(a</span> <span class="pre">//</span> <span class="pre">b,</span> <span class="pre">a</span> <span class="pre">%</span> <span class="pre">b)</span></code>. For floating-point830numbers the result is <code class="docutils literal notranslate"><span class="pre">(q,</span> <span class="pre">a</span> <span class="pre">%</span> <span class="pre">b)</span></code>, where <em>q</em> is usually <code class="docutils literal notranslate"><span class="pre">math.floor(a</span> <span class="pre">/</span>831<span class="pre">b)</span></code> but may be 1 less than that.  In any case <code class="docutils literal notranslate"><span class="pre">q</span> <span class="pre">*</span> <span class="pre">b</span> <span class="pre">+</span> <span class="pre">a</span> <span class="pre">%</span> <span class="pre">b</span></code> is very832close to <em>a</em>, if <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">%</span> <span class="pre">b</span></code> is non-zero it has the same sign as <em>b</em>, and <code class="docutils literal notranslate"><span class="pre">0</span>833<span class="pre">&lt;=</span> <span class="pre">abs(a</span> <span class="pre">%</span> <span class="pre">b)</span> <span class="pre">&lt;</span> <span class="pre">abs(b)</span></code>.</p>834</dd></dl>835 836<dl class="py function">837<dt class="sig sig-object py" id="enumerate">838<span class="sig-name descname"><span class="pre">enumerate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">iterable</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">start</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#enumerate" title="Link to this definition">¶</a></dt>839<dd><p>Return an enumerate object. <em>iterable</em> must be a sequence, an840<a class="reference internal" href="../glossary.html#term-iterator"><span class="xref std std-term">iterator</span></a>, or some other object which supports iteration.841The <a class="reference internal" href="stdtypes.html#iterator.__next__" title="iterator.__next__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__next__()</span></code></a> method of the iterator returned by842<code class="xref py py-func docutils literal notranslate"><span class="pre">enumerate()</span></code> returns a tuple containing a count (from <em>start</em> which843defaults to 0) and the values obtained from iterating over <em>iterable</em>.</p>844<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">seasons</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Spring&#39;</span><span class="p">,</span> <span class="s1">&#39;Summer&#39;</span><span class="p">,</span> <span class="s1">&#39;Fall&#39;</span><span class="p">,</span> <span class="s1">&#39;Winter&#39;</span><span class="p">]</span>845<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="nb">enumerate</span><span class="p">(</span><span class="n">seasons</span><span class="p">))</span>846<span class="go">[(0, &#39;Spring&#39;), (1, &#39;Summer&#39;), (2, &#39;Fall&#39;), (3, &#39;Winter&#39;)]</span>847<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="nb">enumerate</span><span class="p">(</span><span class="n">seasons</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span>848<span class="go">[(1, &#39;Spring&#39;), (2, &#39;Summer&#39;), (3, &#39;Fall&#39;), (4, &#39;Winter&#39;)]</span>849</pre></div>850</div>851<p>Equivalent to:</p>852<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">enumerate</span><span class="p">(</span><span class="n">iterable</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>853    <span class="n">n</span> <span class="o">=</span> <span class="n">start</span>854    <span class="k">for</span> <span class="n">elem</span> <span class="ow">in</span> <span class="n">iterable</span><span class="p">:</span>855        <span class="k">yield</span> <span class="n">n</span><span class="p">,</span> <span class="n">elem</span>856        <span class="n">n</span> <span class="o">+=</span> <span class="mi">1</span>857</pre></div>858</div>859</dd></dl>860 861<dl class="py function" id="func-eval">862<dt class="sig sig-object py" id="eval">863<span class="sig-name descname"><span class="pre">eval</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">globals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#eval" title="Link to this definition">¶</a></dt>864<dd><dl class="field-list simple">865<dt class="field-odd">Parameters<span class="colon">:</span></dt>866<dd class="field-odd"><ul class="simple">867<li><p><strong>source</strong> (<a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> | <a class="reference internal" href="../reference/datamodel.html#code-objects"><span class="std std-ref">code object</span></a>) – A Python expression.</p></li>868<li><p><strong>globals</strong> (<a class="reference internal" href="stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> | <a class="reference internal" href="stdtypes.html#frozendict" title="frozendict"><code class="xref py py-class docutils literal notranslate"><span class="pre">frozendict</span></code></a> | <code class="docutils literal notranslate"><span class="pre">None</span></code>) – The global namespace (default: <code class="docutils literal notranslate"><span class="pre">None</span></code>).</p></li>869<li><p><strong>locals</strong> (<a class="reference internal" href="../glossary.html#term-mapping"><span class="xref std std-term">mapping</span></a> | <code class="docutils literal notranslate"><span class="pre">None</span></code>) – The local namespace (default: <code class="docutils literal notranslate"><span class="pre">None</span></code>).</p></li>870</ul>871</dd>872<dt class="field-even">Returns<span class="colon">:</span></dt>873<dd class="field-even"><p>The result of the evaluated expression.</p>874</dd>875<dt class="field-odd">Raises<span class="colon">:</span></dt>876<dd class="field-odd"><p>Syntax errors are reported as exceptions.</p>877</dd>878</dl>879<div class="admonition warning">880<p class="admonition-title">Warning</p>881<p>This function executes arbitrary code. Calling it with882user-supplied input may lead to security vulnerabilities.</p>883</div>884<p>The <em>source</em> argument is parsed and evaluated as a Python expression885(technically speaking, a condition list) using the <em>globals</em> and <em>locals</em>886mappings as global and local namespace.  If the <em>globals</em> dictionary is887present and does not contain a value for the key <code class="docutils literal notranslate"><span class="pre">__builtins__</span></code>, a888reference to the dictionary of the built-in module <a class="reference internal" href="builtins.html#module-builtins" title="builtins: The module that provides the built-in namespace."><code class="xref py py-mod docutils literal notranslate"><span class="pre">builtins</span></code></a> is889inserted under that key before <em>source</em> is parsed.  That way you can890control what builtins are available to the executed code by inserting your891own <code class="docutils literal notranslate"><span class="pre">__builtins__</span></code> dictionary into <em>globals</em> before passing it to892<code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code>.  If the <em>locals</em> mapping is omitted it defaults to the893<em>globals</em> dictionary.  If both mappings are omitted, the source is894executed with the <em>globals</em> and <em>locals</em> in the environment where895<code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code> is called.  Note, <em>eval()</em> will only have access to the896<a class="reference internal" href="../glossary.html#term-nested-scope"><span class="xref std std-term">nested scopes</span></a> (non-locals) in the enclosing897environment if they are already referenced in the scope that is calling898<code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code> (e.g. via a <a class="reference internal" href="../reference/simple_stmts.html#nonlocal"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">nonlocal</span></code></a> statement).</p>899<p>Example:</p>900<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>901<span class="gp">&gt;&gt;&gt; </span><span class="nb">eval</span><span class="p">(</span><span class="s1">&#39;x+1&#39;</span><span class="p">)</span>902<span class="go">2</span>903</pre></div>904</div>905<p>This function can also be used to execute arbitrary code objects (such as906those created by <a class="reference internal" href="#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a>).  In this case, pass a code object instead907of a string.  If the code object has been compiled with <code class="docutils literal notranslate"><span class="pre">'exec'</span></code> as the908<em>mode</em> argument, <code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code>'s return value will be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>909<p>Hints: dynamic execution of statements is supported by the <a class="reference internal" href="#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a>910function.  The <a class="reference internal" href="#globals" title="globals"><code class="xref py py-func docutils literal notranslate"><span class="pre">globals()</span></code></a> and <a class="reference internal" href="#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> functions911return the current global and local dictionary, respectively, which may be912useful to pass around for use by <code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code> or <code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code>.</p>913<p>If the given source is a string, then leading and trailing spaces and tabs914are stripped.</p>915<p>See <a class="reference internal" href="ast.html#ast.literal_eval" title="ast.literal_eval"><code class="xref py py-func docutils literal notranslate"><span class="pre">ast.literal_eval()</span></code></a> for a function that can safely evaluate strings916with expressions containing only literals.</p>917<p class="audit-hook"><p>Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">exec</span></code> with the code object918as the argument. Code compilation events may also be raised.</p>919</p>920<div class="versionchanged">921<p><span class="versionmodified changed">Changed in version 3.13: </span>The <em>globals</em> and <em>locals</em> arguments can now be passed as keywords.</p>922</div>923<div class="versionchanged">924<p><span class="versionmodified changed">Changed in version 3.13: </span>The semantics of the default <em>locals</em> namespace have been adjusted as925described for the <a class="reference internal" href="#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> builtin.</p>926</div>927<div class="versionchanged">928<p><span class="versionmodified changed">Changed in version 3.15.0a6 (unreleased): </span><em>globals</em> can now be a <a class="reference internal" href="stdtypes.html#frozendict" title="frozendict"><code class="xref py py-class docutils literal notranslate"><span class="pre">frozendict</span></code></a>.</p>929</div>930</dd></dl>931 932<dl class="py function" id="index-2">933<dt class="sig sig-object py" id="exec">934<span class="sig-name descname"><span class="pre">exec</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">globals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">closure</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#exec" title="Link to this definition">¶</a></dt>935<dd><div class="admonition warning">936<p class="admonition-title">Warning</p>937<p>This function executes arbitrary code. Calling it with938user-supplied input may lead to security vulnerabilities.</p>939</div>940<p>This function supports dynamic execution of Python code. <em>source</em> must be941either a string or a code object.  If it is a string, the string is parsed as942a suite of Python statements which is then executed (unless a syntax error943occurs). <a class="footnote-reference brackets" href="#id2" id="id1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a> If it is a code object, it is simply executed.  In all cases,944the code that’s executed is expected to be valid as file input (see the945section <a class="reference internal" href="../reference/toplevel_components.html#file-input"><span class="std std-ref">File input</span></a> in the Reference Manual). Be aware that the946<a class="reference internal" href="../reference/simple_stmts.html#nonlocal"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">nonlocal</span></code></a>, <a class="reference internal" href="../reference/simple_stmts.html#yield"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">yield</span></code></a>,  and <a class="reference internal" href="../reference/simple_stmts.html#return"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">return</span></code></a>947statements may not be used outside of948function definitions even within the context of code passed to the949<code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code> function. The return value is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>950<p>In all cases, if the optional parts are omitted, the code is executed in the951current scope.  If only <em>globals</em> is provided, it must be a dictionary952(and not a subclass of dictionary), which953will be used for both the global and the local variables.  If <em>globals</em> and954<em>locals</em> are given, they are used for the global and local variables,955respectively.  If provided, <em>locals</em> can be any mapping object.  Remember956that at the module level, globals and locals are the same dictionary.</p>957<div class="admonition note">958<p class="admonition-title">Note</p>959<p>When <code class="docutils literal notranslate"><span class="pre">exec</span></code> gets two separate objects as <em>globals</em> and <em>locals</em>, the960code will be executed as if it were embedded in a class definition. This961means functions and classes defined in the executed code will not be able962to access variables assigned at the top level (as the “top level”963variables are treated as class variables in a class definition).</p>964</div>965<p>If the <em>globals</em> dictionary does not contain a value for the key966<code class="docutils literal notranslate"><span class="pre">__builtins__</span></code>, a reference to the dictionary of the built-in module967<a class="reference internal" href="builtins.html#module-builtins" title="builtins: The module that provides the built-in namespace."><code class="xref py py-mod docutils literal notranslate"><span class="pre">builtins</span></code></a> is inserted under that key.  That way you can control what968builtins are available to the executed code by inserting your own969<code class="docutils literal notranslate"><span class="pre">__builtins__</span></code> dictionary into <em>globals</em> before passing it to <code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code>.</p>970<p>The <em>closure</em> argument specifies a closure–a tuple of cellvars.971It’s only valid when the <em>object</em> is a code object containing972<a class="reference internal" href="../glossary.html#term-closure-variable"><span class="xref std std-term">free (closure) variables</span></a>.973The length of the tuple must exactly match the length of the code object’s974<a class="reference internal" href="../reference/datamodel.html#codeobject.co_freevars" title="codeobject.co_freevars"><code class="xref py py-attr docutils literal notranslate"><span class="pre">co_freevars</span></code></a> attribute.</p>975<p class="audit-hook"><p>Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">exec</span></code> with the code object976as the argument. Code compilation events may also be raised.</p>977</p>978<div class="admonition note">979<p class="admonition-title">Note</p>980<p>The built-in functions <a class="reference internal" href="#globals" title="globals"><code class="xref py py-func docutils literal notranslate"><span class="pre">globals()</span></code></a> and <a class="reference internal" href="#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> return the current981global and local namespace, respectively, which may be useful to pass around982for use as the second and third argument to <code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code>.</p>983</div>984<div class="admonition note">985<p class="admonition-title">Note</p>986<p>The default <em>locals</em> act as described for function <a class="reference internal" href="#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> below.987Pass an explicit <em>locals</em> dictionary if you need to see effects of the988code on <em>locals</em> after function <code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code> returns.</p>989</div>990<div class="versionchanged">991<p><span class="versionmodified changed">Changed in version 3.11: </span>Added the <em>closure</em> parameter.</p>992</div>993<div class="versionchanged">994<p><span class="versionmodified changed">Changed in version 3.13: </span>The <em>globals</em> and <em>locals</em> arguments can now be passed as keywords.</p>995</div>996<div class="versionchanged">997<p><span class="versionmodified changed">Changed in version 3.13: </span>The semantics of the default <em>locals</em> namespace have been adjusted as998described for the <a class="reference internal" href="#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> builtin.</p>999</div>1000<div class="versionchanged">1001<p><span class="versionmodified changed">Changed in version 3.15.0a6 (unreleased): </span><em>globals</em> can now be a <a class="reference internal" href="stdtypes.html#frozendict" title="frozendict"><code class="xref py py-class docutils literal notranslate"><span class="pre">frozendict</span></code></a>.</p>1002</div>1003</dd></dl>1004 1005<dl class="py function">1006<dt class="sig sig-object py" id="filter">1007<span class="sig-name descname"><span class="pre">filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">iterable</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#filter" title="Link to this definition">¶</a></dt>1008<dd><p>Construct an iterator from those elements of <em>iterable</em> for which <em>function</em>1009is true.  <em>iterable</em> may be either a sequence, a container which1010supports iteration, or an iterator.  If <em>function</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, the identity1011function is assumed, that is, all elements of <em>iterable</em> that are false are1012removed.</p>1013<p>Note that <code class="docutils literal notranslate"><span class="pre">filter(function,</span> <span class="pre">iterable)</span></code> is equivalent to the generator1014expression <code class="docutils literal notranslate"><span class="pre">(item</span> <span class="pre">for</span> <span class="pre">item</span> <span class="pre">in</span> <span class="pre">iterable</span> <span class="pre">if</span> <span class="pre">function(item))</span></code> if function is1015not <code class="docutils literal notranslate"><span class="pre">None</span></code> and <code class="docutils literal notranslate"><span class="pre">(item</span> <span class="pre">for</span> <span class="pre">item</span> <span class="pre">in</span> <span class="pre">iterable</span> <span class="pre">if</span> <span class="pre">item)</span></code> if function is1016<code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>1017<p>See <a class="reference internal" href="itertools.html#itertools.filterfalse" title="itertools.filterfalse"><code class="xref py py-func docutils literal notranslate"><span class="pre">itertools.filterfalse()</span></code></a> for the complementary function that returns1018elements of <em>iterable</em> for which <em>function</em> is false.</p>1019</dd></dl>1020 1021<dl class="py class">1022<dt class="sig sig-object py" id="float">1023<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">float</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">number</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.0</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#float" title="Link to this definition">¶</a></dt>1024<dt class="sig sig-object py">1025<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">float</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span></dt>1026<dd><p id="index-3">Return a floating-point number constructed from a number or a string.</p>1027<p>Examples:</p>1028<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">float</span><span class="p">(</span><span class="s1">&#39;+1.23&#39;</span><span class="p">)</span>1029<span class="go">1.23</span>1030<span class="gp">&gt;&gt;&gt; </span><span class="nb">float</span><span class="p">(</span><span class="s1">&#39;   -12345</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>1031<span class="go">-12345.0</span>1032<span class="gp">&gt;&gt;&gt; </span><span class="nb">float</span><span class="p">(</span><span class="s1">&#39;1e-003&#39;</span><span class="p">)</span>1033<span class="go">0.001</span>1034<span class="gp">&gt;&gt;&gt; </span><span class="nb">float</span><span class="p">(</span><span class="s1">&#39;+1E6&#39;</span><span class="p">)</span>1035<span class="go">1000000.0</span>1036<span class="gp">&gt;&gt;&gt; </span><span class="nb">float</span><span class="p">(</span><span class="s1">&#39;-Infinity&#39;</span><span class="p">)</span>1037<span class="go">-inf</span>1038</pre></div>1039</div>1040<p>If the argument is a string, it should contain a decimal number, optionally1041preceded by a sign, and optionally embedded in whitespace.  The optional1042sign may be <code class="docutils literal notranslate"><span class="pre">'+'</span></code> or <code class="docutils literal notranslate"><span class="pre">'-'</span></code>; a <code class="docutils literal notranslate"><span class="pre">'+'</span></code> sign has no effect on the value1043produced.  The argument may also be a string representing a NaN1044(not-a-number), or positive or negative infinity.1045More precisely, the input must conform to the <a class="reference internal" href="#grammar-token-float-floatvalue"><code class="xref std std-token docutils literal notranslate"><span class="pre">floatvalue</span></code></a>1046production rule in the following grammar, after leading and trailing1047whitespace characters are removed:</p>1048<pre class="highlight">1049<strong id="grammar-token-float-sign">sign</strong>:          <span class="sx">&quot;+&quot;</span> | <span class="sx">&quot;-&quot;</span>1050<strong id="grammar-token-float-infinity">infinity</strong>:      <span class="sx">&quot;Infinity&quot;</span> | <span class="sx">&quot;inf&quot;</span>1051<strong id="grammar-token-float-nan">nan</strong>:           <span class="sx">&quot;nan&quot;</span>1052<strong id="grammar-token-float-digit">digit</strong>:         &lt;a Unicode decimal digit, i.e. characters in Unicode general category Nd&gt;1053<strong id="grammar-token-float-digitpart">digitpart</strong>:     <a class="reference internal" href="#grammar-token-float-digit"><code class="xref docutils literal notranslate"><span class="pre">digit</span></code></a> ([<span class="sx">&quot;_&quot;</span>] <a class="reference internal" href="#grammar-token-float-digit"><code class="xref docutils literal notranslate"><span class="pre">digit</span></code></a>)*1054<strong id="grammar-token-float-number">number</strong>:        [<a class="reference internal" href="#grammar-token-float-digitpart"><code class="xref docutils literal notranslate"><span class="pre">digitpart</span></code></a>] <span class="sx">&quot;.&quot;</span> <a class="reference internal" href="#grammar-token-float-digitpart"><code class="xref docutils literal notranslate"><span class="pre">digitpart</span></code></a> | <a class="reference internal" href="#grammar-token-float-digitpart"><code class="xref docutils literal notranslate"><span class="pre">digitpart</span></code></a> [<span class="sx">&quot;.&quot;</span>]1055<strong id="grammar-token-float-exponent">exponent</strong>:      (<span class="sx">&quot;e&quot;</span> | <span class="sx">&quot;E&quot;</span>) [<a class="reference internal" href="#grammar-token-float-sign"><code class="xref docutils literal notranslate"><span class="pre">sign</span></code></a>] <a class="reference internal" href="#grammar-token-float-digitpart"><code class="xref docutils literal notranslate"><span class="pre">digitpart</span></code></a>1056<strong id="grammar-token-float-floatnumber">floatnumber</strong>:   <a class="reference internal" href="#grammar-token-float-number"><code class="xref docutils literal notranslate"><span class="pre">number</span></code></a> [<a class="reference internal" href="#grammar-token-float-exponent"><code class="xref docutils literal notranslate"><span class="pre">exponent</span></code></a>]1057<strong id="grammar-token-float-absfloatvalue">absfloatvalue</strong>: <a class="reference internal" href="#grammar-token-float-floatnumber"><code class="xref docutils literal notranslate"><span class="pre">floatnumber</span></code></a> | <a class="reference internal" href="#grammar-token-float-infinity"><code class="xref docutils literal notranslate"><span class="pre">infinity</span></code></a> | <a class="reference internal" href="#grammar-token-float-nan"><code class="xref docutils literal notranslate"><span class="pre">nan</span></code></a>1058<strong id="grammar-token-float-floatvalue">floatvalue</strong>:    [<a class="reference internal" href="#grammar-token-float-sign"><code class="xref docutils literal notranslate"><span class="pre">sign</span></code></a>] <a class="reference internal" href="#grammar-token-float-absfloatvalue"><code class="xref docutils literal notranslate"><span class="pre">absfloatvalue</span></code></a>1059</pre>1060<p>Case is not significant, so, for example, “inf”, “Inf”, “INFINITY”, and1061“iNfINity” are all acceptable spellings for positive infinity.</p>1062<p>Otherwise, if the argument is an integer or a floating-point number, a1063floating-point number with the same value (within Python’s floating-point1064precision) is returned.  If the argument is outside the range of a Python1065float, an <a class="reference internal" href="exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a> will be raised.</p>1066<p>For a general Python object <code class="docutils literal notranslate"><span class="pre">x</span></code>, <code class="docutils literal notranslate"><span class="pre">float(x)</span></code> delegates to1067<code class="docutils literal notranslate"><span class="pre">x.__float__()</span></code>.  If <a class="reference internal" href="../reference/datamodel.html#object.__float__" title="object.__float__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__float__()</span></code></a> is not defined then it falls back1068to <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a>.</p>1069<p>See also <a class="reference internal" href="stdtypes.html#float.from_number" title="float.from_number"><code class="xref py py-meth docutils literal notranslate"><span class="pre">float.from_number()</span></code></a> which only accepts a numeric argument.</p>1070<p>If no argument is given, <code class="docutils literal notranslate"><span class="pre">0.0</span></code> is returned.</p>1071<p>The float type is described in <a class="reference internal" href="stdtypes.html#typesnumeric"><span class="std std-ref">Numeric Types — int, float, complex</span></a>.</p>1072<div class="versionchanged">1073<p><span class="versionmodified changed">Changed in version 3.6: </span>Grouping digits with underscores as in code literals is allowed.</p>1074</div>1075<div class="versionchanged">1076<p><span class="versionmodified changed">Changed in version 3.7: </span>The parameter is now positional-only.</p>1077</div>1078<div class="versionchanged">1079<p><span class="versionmodified changed">Changed in version 3.8: </span>Falls back to <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> if <a class="reference internal" href="../reference/datamodel.html#object.__float__" title="object.__float__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__float__()</span></code></a> is not defined.</p>1080</div>1081</dd></dl>1082 1083<dl class="py function" id="index-4">1084<dt class="sig sig-object py" id="format">1085<span class="sig-name descname"><span class="pre">format</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">format_spec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#format" title="Link to this definition">¶</a></dt>1086<dd><p>Convert a <em>value</em> to a “formatted” representation, as controlled by1087<em>format_spec</em>.  The interpretation of <em>format_spec</em> will depend on the type1088of the <em>value</em> argument; however, there is a standard formatting syntax that1089is used by most built-in types: <a class="reference internal" href="string.html#formatspec"><span class="std std-ref">Format Specification Mini-Language</span></a>.</p>1090<p>The default <em>format_spec</em> is an empty string which usually gives the same1091effect as calling <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str(value)</span></code></a>.</p>1092<p>A call to <code class="docutils literal notranslate"><span class="pre">format(value,</span> <span class="pre">format_spec)</span></code> is translated to1093<code class="docutils literal notranslate"><span class="pre">type(value).__format__(value,</span> <span class="pre">format_spec)</span></code> which bypasses the instance1094dictionary when searching for the value’s <a class="reference internal" href="../reference/datamodel.html#object.__format__" title="object.__format__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__format__()</span></code></a> method.1095A <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> exception is raised if the method search reaches1096<a class="reference internal" href="#object" title="object"><code class="xref py py-mod docutils literal notranslate"><span class="pre">object</span></code></a> and the <em>format_spec</em> is non-empty, or if either the1097<em>format_spec</em> or the return value are not strings.</p>1098<div class="versionchanged">1099<p><span class="versionmodified changed">Changed in version 3.4: </span><code class="docutils literal notranslate"><span class="pre">object().__format__(format_spec)</span></code> raises <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>1100if <em>format_spec</em> is not an empty string.</p>1101</div>1102</dd></dl>1103 1104<dl class="py class" id="func-frozenset">1105<dt class="sig sig-object py">1106<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">frozenset</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">iterable</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span></dt>1107<dd><p>Return a new <code class="xref py py-class docutils literal notranslate"><span class="pre">frozenset</span></code> object, optionally with elements taken from1108<em>iterable</em>.  <code class="docutils literal notranslate"><span class="pre">frozenset</span></code> is a built-in class.  See <code class="xref py py-class docutils literal notranslate"><span class="pre">frozenset</span></code> and1109<a class="reference internal" href="stdtypes.html#types-set"><span class="std std-ref">Set Types — set, frozenset</span></a> for documentation about this class.</p>1110<p>For other containers see the built-in <a class="reference internal" href="stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>, <a class="reference internal" href="stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>,1111<a class="reference internal" href="stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a>, and <a class="reference internal" href="stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> classes, as well as the <a class="reference internal" href="collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a>1112module.</p>1113</dd></dl>1114 1115<dl class="py function">1116<dt class="sig sig-object py" id="getattr">1117<span class="sig-name descname"><span class="pre">getattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#getattr" title="Link to this definition">¶</a></dt>1118<dt class="sig sig-object py">1119<span class="sig-name descname"><span class="pre">getattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span></dt>1120<dd><p>Return the value of the named attribute of <em>object</em>.  <em>name</em> must be a string.1121If the string is the name of one of the object’s attributes, the result is the1122value of that attribute.  For example, <code class="docutils literal notranslate"><span class="pre">getattr(x,</span> <span class="pre">'foobar')</span></code> is equivalent to1123<code class="docutils literal notranslate"><span class="pre">x.foobar</span></code>.  If the named attribute does not exist, <em>default</em> is returned if1124provided, otherwise <a class="reference internal" href="exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a> is raised.1125<em>name</em> need not be a Python identifier (see <a class="reference internal" href="#setattr" title="setattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">setattr()</span></code></a>).</p>1126<div class="admonition note">1127<p class="admonition-title">Note</p>1128<p>Since <a class="reference internal" href="../reference/expressions.html#private-name-mangling"><span class="std std-ref">private name mangling</span></a> happens at1129compilation time, one must manually mangle a private attribute’s1130(attributes with two leading underscores) name in order to retrieve it with1131<code class="xref py py-func docutils literal notranslate"><span class="pre">getattr()</span></code>.</p>1132</div>1133</dd></dl>1134 1135<dl class="py function">1136<dt class="sig sig-object py" id="globals">1137<span class="sig-name descname"><span class="pre">globals</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#globals" title="Link to this definition">¶</a></dt>1138<dd><p>Return the dictionary implementing the current module namespace. For code within1139functions, this is set when the function is defined and remains the same1140regardless of where the function is called.</p>1141</dd></dl>1142 1143<dl class="py function">1144<dt class="sig sig-object py" id="hasattr">1145<span class="sig-name descname"><span class="pre">hasattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#hasattr" title="Link to this definition">¶</a></dt>1146<dd><p>The arguments are an object and a string.  The result is <code class="docutils literal notranslate"><span class="pre">True</span></code> if the1147string is the name of one of the object’s attributes, <code class="docutils literal notranslate"><span class="pre">False</span></code> if not. (This1148is implemented by calling <code class="docutils literal notranslate"><span class="pre">getattr(object,</span> <span class="pre">name)</span></code> and seeing whether it1149raises an <a class="reference internal" href="exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a> or not.)</p>1150</dd></dl>1151 1152<dl class="py function">1153<dt class="sig sig-object py" id="hash">1154<span class="sig-name descname"><span class="pre">hash</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#hash" title="Link to this definition">¶</a></dt>1155<dd><p>Return the hash value of the object (if it has one).  Hash values are1156integers.  They are used to quickly compare dictionary keys during a1157dictionary lookup.  Numeric values that compare equal have the same hash1158value (even if they are of different types, as is the case for 1 and 1.0).</p>1159<div class="admonition note">1160<p class="admonition-title">Note</p>1161<p>For objects with custom <a class="reference internal" href="../reference/datamodel.html#object.__hash__" title="object.__hash__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__hash__()</span></code></a> methods,1162note that <code class="xref py py-func docutils literal notranslate"><span class="pre">hash()</span></code>1163truncates the return value based on the bit width of the host machine.</p>1164</div>1165</dd></dl>1166 1167<dl class="py function">1168<dt class="sig sig-object py" id="help">1169<span class="sig-name descname"><span class="pre">help</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#help" title="Link to this definition">¶</a></dt>1170<dt class="sig sig-object py">1171<span class="sig-name descname"><span class="pre">help</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">request</span></span></em><span class="sig-paren">)</span></dt>1172<dd><p>Invoke the built-in help system.  (This function is intended for interactive1173use.)  If no argument is given, the interactive help system starts on the1174interpreter console.  If the argument is a string, then the string is looked up1175as the name of a module, function, class, method, keyword, or documentation1176topic, and a help page is printed on the console.  If the argument is any other1177kind of object, a help page on the object is generated.</p>1178<p>Note that if a slash(/) appears in the parameter list of a function when1179invoking <code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code>, it means that the parameters prior to the slash are1180positional-only. For more info, see1181<a class="reference internal" href="../faq/programming.html#faq-positional-only-arguments"><span class="std std-ref">the FAQ entry on positional-only parameters</span></a>.</p>1182<p>This function is added to the built-in namespace 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.</p>1183<div class="versionchanged">1184<p><span class="versionmodified changed">Changed in version 3.4: </span>Changes to <a class="reference internal" href="pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> and <a class="reference internal" href="inspect.html#module-inspect" title="inspect: Extract information and source code from live objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">inspect</span></code></a> mean that the reported1185signatures for callables are now more comprehensive and consistent.</p>1186</div>1187</dd></dl>1188 1189<dl class="py function">1190<dt class="sig sig-object py" id="hex">1191<span class="sig-name descname"><span class="pre">hex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">integer</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#hex" title="Link to this definition">¶</a></dt>1192<dd><p>Convert an integer number to a lowercase hexadecimal string prefixed with1193“0x”. If <em>integer</em> is not a Python <a class="reference internal" href="#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> object, it has to define an1194<a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> method that returns an integer. Some examples:</p>1195<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">hex</span><span class="p">(</span><span class="mi">255</span><span class="p">)</span>1196<span class="go">&#39;0xff&#39;</span>1197<span class="gp">&gt;&gt;&gt; </span><span class="nb">hex</span><span class="p">(</span><span class="o">-</span><span class="mi">42</span><span class="p">)</span>1198<span class="go">&#39;-0x2a&#39;</span>1199</pre></div>1200</div>

Showing the first 1,200 of 2634 lines. Download the file for the rest.