Browse Source

ABC

pull/31/head
Jure Šorn 5 years ago
parent
commit
030e49f5e4
2 changed files with 18 additions and 6 deletions
  1. 13
      README.md
  2. 11
      index.html

13
README.md

@ -245,12 +245,19 @@ Type
from types import FunctionType, MethodType, LambdaType, GeneratorType
```
### ABC-s
**Abstract base classes introduce virtual subclasses, that don’t inherit from a class but are still recognized by isinstance() and issubclass().**
### ABC
**An abstract base class introduces virtual subclasses, that don’t inherit from it but are still recognized by isinstance() and issubclass().**
```python
from numbers import Integral, Rational, Real, Complex, Number
from collections.abc import Iterable, Collection, Sequence
from collections.abc import Sequence, Collection, Iterable
```
```python
>>> isinstance(123, Number)
True
>>> isinstance([1, 2, 3], Iterable)
True
```

11
index.html

@ -316,10 +316,15 @@ Point(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>
<h4 id="sometypesdonothavebuiltinnamessotheymustbeimported">Some types do not have builtin 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
</code></pre>
<h3 id="abcs">ABC-s</h3>
<p><strong>Abstract base classes introduce virtual subclasses, that don’t inherit from a class but are still recognized by isinstance() and issubclass().</strong></p>
<h3 id="abc">ABC</h3>
<p><strong>An abstract base class introduces virtual subclasses, that don’t inherit from it but are still recognized by isinstance() and issubclass().</strong></p>
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> numbers <span class="hljs-keyword">import</span> Integral, Rational, Real, Complex, Number
<span class="hljs-keyword">from</span> collections.abc <span class="hljs-keyword">import</span> Iterable, Collection, Sequence
<span class="hljs-keyword">from</span> collections.abc <span class="hljs-keyword">import</span> Sequence, Collection, Iterable
</code></pre>
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>isinstance(<span class="hljs-number">123</span>, Number)
<span class="hljs-keyword">True</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>isinstance([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], Iterable)
<span class="hljs-keyword">True</span>
</code></pre>
<h2 id="string"><a href="#string" name="string">#</a>String</h2>
<pre><code class="python language-python hljs">&lt;str&gt; = &lt;str&gt;.strip() <span class="hljs-comment"># Strips all whitespace characters from both ends.</span>

Loading…
Cancel
Save