|
392 | 392 | <div><h4 id="sometypesdonothavebuiltinnamessotheymustbeimported">Some types do not have built-in names, so they must be imported:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> types <span class="hljs-keyword">import</span> FunctionType, MethodType, LambdaType, GeneratorType
|
393 | 393 | </code></pre></div>
|
394 | 394 |
|
395 |
| -<div><h3 id="abstractbaseclasses">Abstract Base Classes</h3><p><strong>Each abstract base class specifies a set of virtual subclasses. This classes get recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not.</strong></p><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> collections.abc <span class="hljs-keyword">import</span> Sequence, Collection, Iterable |
| 395 | +<div><h3 id="abstractbaseclasses">Abstract Base Classes</h3><p><strong>Each abstract base class specifies a set of virtual subclasses. This classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not.</strong></p><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> collections.abc <span class="hljs-keyword">import</span> Sequence, Collection, Iterable |
396 | 396 | <span class="hljs-meta">>>> </span>isinstance([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], Iterable)
|
397 | 397 | <span class="hljs-keyword">True</span>
|
398 | 398 | </code></pre></div>
|
|
582 | 582 | <num> = round(<num> [, ±ndigits]) <span class="hljs-comment"># `round(126, -1) == 130`</span>
|
583 | 583 | </code></pre></div>
|
584 | 584 |
|
585 |
| -<div><h3 id="math">Math</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> math <span class="hljs-keyword">import</span> e, pi, inf, nan |
| 585 | +<div><h3 id="math">Math</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> math <span class="hljs-keyword">import</span> e, pi, inf, nan, isinf, isnan |
586 | 586 | <span class="hljs-keyword">from</span> math <span class="hljs-keyword">import</span> cos, acos, sin, asin, tan, atan, degrees, radians
|
587 | 587 | <span class="hljs-keyword">from</span> math <span class="hljs-keyword">import</span> log, log10, log2
|
588 | 588 | </code></pre></div>
|
|
1194 | 1194 | </code></pre></div>
|
1195 | 1195 |
|
1196 | 1196 |
|
1197 |
| -<div><h3 id="collectionsabcsequence">Collections.abc.Sequence</h3><ul> |
| 1197 | +<div><h3 id="abcsequence">ABC Sequence</h3><ul> |
1198 | 1198 | <li><strong>It's a richer interface than the basic sequence.</strong></li>
|
1199 | 1199 | <li><strong>Extending it generates iter(), contains(), reversed(), index() and count().</strong></li>
|
1200 | 1200 | <li><strong>Unlike <code class="python hljs"><span class="hljs-string">'abc.Iterable'</span></code> and <code class="python hljs"><span class="hljs-string">'abc.Collection'</span></code>, it is not a duck type. That is why <code class="python hljs"><span class="hljs-string">'issubclass(MySequence, abc.Sequence)'</span></code> would return False even if MySequence had all the methods defined.</strong></li>
|
|
1329 | 1329 | +-- NameError # Raised when a variable name is not found.
|
1330 | 1330 | +-- OSError # Failures such as “file not found” or “disk full”.
|
1331 | 1331 | | +-- FileNotFoundError # When a file or directory is requested but doesn't exist.
|
1332 |
| - +-- RuntimeError # Raised by errors that don't fall in other categories. |
| 1332 | + +-- RuntimeError # Raised by errors that don't fall into other categories. |
1333 | 1333 | | +-- RecursionError # Raised when the maximum recursion depth is exceeded.
|
1334 | 1334 | +-- StopIteration # Raised by next() when run on an empty iterator.
|
1335 | 1335 | +-- TypeError # Raised when an argument is of wrong type.
|
|
1361 | 1361 |
|
1362 | 1362 | <div><h2 id="exit"><a href="#exit" name="exit">#</a>Exit</h2><p><strong>Exits the interpreter by raising SystemExit exception.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sys
|
1363 | 1363 | sys.exit() <span class="hljs-comment"># Exits with exit code 0 (success).</span>
|
1364 |
| -sys.exit(<int>) <span class="hljs-comment"># Exits with passed exit code.</span> |
1365 |
| -sys.exit(<obj>) <span class="hljs-comment"># Prints the object and exits with 1 (failure).</span> |
| 1364 | +sys.exit(<el>) <span class="hljs-comment"># Prints object to stderr and exits with 1.</span> |
| 1365 | +sys.exit(<int>) <span class="hljs-comment"># Exits with the passed exit code.</span> |
1366 | 1366 | </code></pre></div>
|
1367 | 1367 |
|
1368 | 1368 |
|
|
0 commit comments