You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Each abstract base class specifies a set of virtual subclasses. These classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not. ABC can also manually decide whether or not a specific class is its virtual subclass, usually based on which methods the class has implemented. For instance, Iterable ABC looks for method iter()while Collection ABC looks for methods iter(), contains() and len().**
265
+
**Each abstract base class specifies a set of virtual subclasses. These classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not. ABC can also manually decide whether or not a specific class is its virtual subclass, usually based on which methods the class has implemented. For instance, Collection ABC looks for methods iter(), contains() and len(), while Iterable ABC only looks for method iter().**
<div><h4id="sometypesdonothavebuiltinnamessotheymustbeimported">Some types do not have built-in names, so they must be imported:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> types <spanclass="hljs-keyword">import</span> FunctionType, MethodType, LambdaType, GeneratorType, ModuleType
264
264
</code></pre></div>
265
265
266
-
<div><h3id="abstractbaseclasses">Abstract Base Classes</h3><p><strong>Each abstract base class specifies a set of virtual subclasses. These classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not. ABC can also manually decide whether or not a specific class is its virtual subclass, usually based on which methods the class has implemented. For instance, Iterable ABC looks for method iter()while Collection ABC looks for methods iter(), contains() and len().</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>> </span><spanclass="hljs-keyword">from</span> collections.abc <spanclass="hljs-keyword">import</span> Sequence, Collection, Iterable
266
+
<div><h3id="abstractbaseclasses">Abstract Base Classes</h3><p><strong>Each abstract base class specifies a set of virtual subclasses. These classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not. ABC can also manually decide whether or not a specific class is its virtual subclass, usually based on which methods the class has implemented. For instance, Collection ABC looks for methods iter(), contains() and len(), while Iterable ABC only looks for method iter().</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>> </span><spanclass="hljs-keyword">from</span> collections.abc <spanclass="hljs-keyword">import</span> Sequence, Collection, Iterable
<bool> = <str>.startswith(<sub_str>) <spanclass="hljs-comment"># Pass tuple of strings for multiple options.</span>
305
305
<bool> = <str>.endswith(<sub_str>) <spanclass="hljs-comment"># Pass tuple of strings for multiple options.</span>
306
306
<int> = <str>.find(<sub_str>) <spanclass="hljs-comment"># Returns start index of the first match or -1.</span>
307
-
<int> = <str>.index(<sub_str>) <spanclass="hljs-comment"># Same but raises ValueError if missing.</span>
307
+
<int> = <str>.index(<sub_str>) <spanclass="hljs-comment"># Same, but raises ValueError if missing.</span>
308
308
</code></pre>
309
309
<pre><codeclass="python language-python hljs"><str> = <str>.replace(old, new [, count]) <spanclass="hljs-comment"># Replaces 'old' with 'new' at most 'count' times.</span>
310
310
<str> = <str>.translate(<table>) <spanclass="hljs-comment"># Use `str.maketrans(<dict>)` to generate table.</span>
0 commit comments