Skip to content

Commit 311c4a7

Browse files
committed
Type
1 parent 6a532b0 commit 311c4a7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ Type
231231
* **Type and class are synonymous.**
232232

233233
```python
234-
<type> = type(<el>) # Or: <type> = <el>.__class__
235-
<bool> = isinstance(<el>, <type>) # Also checks subclasses and ABCs.
234+
<type> = type(<el>) # Or: <el>.__class__
235+
<bool> = isinstance(<el>, <type>) # Or: issubclass(type(<el>), <type>)
236236
```
237237

238238
```python
@@ -246,7 +246,7 @@ from types import FunctionType, MethodType, LambdaType, GeneratorType
246246
```
247247

248248
### ABC-s
249-
**Abstract base classes introduce virtual subclasses, that don’t inherit from a class but are still recognized by isinstance().**
249+
**Abstract base classes introduce virtual subclasses, that don’t inherit from a class but are still recognized by isinstance() and issubclass().**
250250

251251
```python
252252
from numbers import Integral, Rational, Real, Complex, Number

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ <h2 id="type"><a href="#type" name="type">#</a>Type</h2>
307307
<li><strong>Every object has a type.</strong></li>
308308
<li><strong>Type and class are synonymous.</strong></li>
309309
</ul>
310-
<pre><code class="python language-python hljs">&lt;type&gt; = type(&lt;el&gt;) <span class="hljs-comment"># Or: &lt;type&gt; = &lt;el&gt;.__class__</span>
311-
&lt;bool&gt; = isinstance(&lt;el&gt;, &lt;type&gt;) <span class="hljs-comment"># Also checks subclasses and ABCs.</span>
310+
<pre><code class="python language-python hljs">&lt;type&gt; = type(&lt;el&gt;) <span class="hljs-comment"># Or: &lt;el&gt;.__class__</span>
311+
&lt;bool&gt; = isinstance(&lt;el&gt;, &lt;type&gt;) <span class="hljs-comment"># Or: issubclass(type(&lt;el&gt;), &lt;type&gt;)</span>
312312
</code></pre>
313313
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>type(<span class="hljs-string">'a'</span>), <span class="hljs-string">'a'</span>.__class__, str
314314
(&lt;<span class="hljs-class"><span class="hljs-title">class</span> '<span class="hljs-title">str</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">str</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">str</span>'&gt;)
@@ -317,7 +317,7 @@ <h4 id="sometypesdonothavebuiltinnamessotheymustbeimported">Some types do not ha
317317
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> types <span class="hljs-keyword">import</span> FunctionType, MethodType, LambdaType, GeneratorType
318318
</code></pre>
319319
<h3 id="abcs">ABC-s</h3>
320-
<p><strong>Abstract base classes introduce virtual subclasses, that don’t inherit from a class but are still recognized by isinstance().</strong></p>
320+
<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>
321321
<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
322322
<span class="hljs-keyword">from</span> collections.abc <span class="hljs-keyword">import</span> Iterable, Collection, Sequence
323323
</code></pre>

0 commit comments

Comments
 (0)