Browse Source

Type, String

pull/121/head
Jure Šorn 2 years ago
parent
commit
63a85ba7e9
3 changed files with 50 additions and 6 deletions
  1. 4
      README.md
  2. 8
      index.html
  3. 44
      parse.js

4
README.md

@ -262,7 +262,7 @@ from types import FunctionType, MethodType, LambdaType, GeneratorType, ModuleTyp
```
### Abstract Base Classes
**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().**
**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().**
```python
>>> from collections.abc import Sequence, Collection, Iterable
@ -318,7 +318,7 @@ String
<bool> = <str>.startswith(<sub_str>) # Pass tuple of strings for multiple options.
<bool> = <str>.endswith(<sub_str>) # Pass tuple of strings for multiple options.
<int> = <str>.find(<sub_str>) # Returns start index of the first match or -1.
<int> = <str>.index(<sub_str>) # Same but raises ValueError if missing.
<int> = <str>.index(<sub_str>) # Same, but raises ValueError if missing.
```
```python

8
index.html

@ -54,7 +54,7 @@
<body>
<header>
<aside>February 6, 2022</aside>
<aside>February 13, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -263,7 +263,7 @@ to_exclusive = &lt;range&gt;.stop
<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, ModuleType
</code></pre></div>
<div><h3 id="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><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> collections.abc <span class="hljs-keyword">import</span> Sequence, Collection, Iterable
<div><h3 id="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><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> collections.abc <span class="hljs-keyword">import</span> Sequence, Collection, Iterable
<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></div>
@ -304,7 +304,7 @@ to_exclusive = &lt;range&gt;.stop
&lt;bool&gt; = &lt;str&gt;.startswith(&lt;sub_str&gt;) <span class="hljs-comment"># Pass tuple of strings for multiple options.</span>
&lt;bool&gt; = &lt;str&gt;.endswith(&lt;sub_str&gt;) <span class="hljs-comment"># Pass tuple of strings for multiple options.</span>
&lt;int&gt; = &lt;str&gt;.find(&lt;sub_str&gt;) <span class="hljs-comment"># Returns start index of the first match or -1.</span>
&lt;int&gt; = &lt;str&gt;.index(&lt;sub_str&gt;) <span class="hljs-comment"># Same but raises ValueError if missing.</span>
&lt;int&gt; = &lt;str&gt;.index(&lt;sub_str&gt;) <span class="hljs-comment"># Same, but raises ValueError if missing.</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;str&gt; = &lt;str&gt;.replace(old, new [, count]) <span class="hljs-comment"># Replaces 'old' with 'new' at most 'count' times.</span>
&lt;str&gt; = &lt;str&gt;.translate(&lt;table&gt;) <span class="hljs-comment"># Use `str.maketrans(&lt;dict&gt;)` to generate table.</span>
@ -2883,7 +2883,7 @@ $ pyinstaller script.py --add-data '&lt;path&gt;:.' <span class="hljs-comment">
<footer>
<aside>February 6, 2022</aside>
<aside>February 13, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

44
parse.js

@ -115,6 +115,15 @@ const DIAGRAM_1_B =
'┃ iter │ │ │ ✓ ┃\n' +
'┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┛\n';
// const DIAGRAM_1_B =
// '┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┓\n' +
// '┃ │ Iterable │ Collection │ Sequence ┃\n' +
// '┠──────────────────┼────────────┼────────────┼────────────┨\n' +
// '┃ list, range, str │ ✓ │ ✓ │ ✓ ┃\n' +
// '┃ dict, set │ ✓ │ ✓ │ ┃\n' +
// '┃ iter │ ✓ │ │ ┃\n' +
// '┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┛\n';
const DIAGRAM_2_A =
'+--------------------+----------+----------+----------+----------+----------+\n' +
'| | Integral | Rational | Real | Complex | Number |\n' +
@ -131,6 +140,17 @@ const DIAGRAM_2_B =
'┃ decimal.Decimal │ │ │ │ │ ✓ ┃\n' +
'┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛\n';
// const DIAGRAM_2_B =
// '┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┓\n' +
// '┃ │ Number │ Complex │ Real │ Rational │ Integral ┃\n' +
// '┠────────────────────┼──────────┼──────────┼──────────┼──────────┼──────────┨\n' +
// '┃ int │ ✓ │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
// '┃ fractions.Fraction │ ✓ │ ✓ │ ✓ │ ✓ │ ┃\n' +
// '┃ float │ ✓ │ ✓ │ ✓ │ │ ┃\n' +
// '┃ complex │ ✓ │ ✓ │ │ │ ┃\n' +
// '┃ decimal.Decimal │ ✓ │ │ │ │ ┃\n' +
// '┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛\n';
const DIAGRAM_3_A =
'+---------------+----------+----------+----------+----------+----------+\n';
@ -145,6 +165,17 @@ const DIAGRAM_3_B =
'┃ isdecimal() │ │ │ │ │ ✓ ┃\n' +
'┗━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛\n';
// const DIAGRAM_3_B =
// '┏━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┓\n' +
// '┃ │ [0-9] │ [²³¹] │ [¼½¾] │ [a-zA-Z] │ [ !#$%…] ┃\n' +
// '┠───────────────┼──────────┼──────────┼──────────┼──────────┼──────────┨\n' +
// '┃ isprintable() │ ✓ │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
// '┃ isalnum() │ ✓ │ ✓ │ ✓ │ ✓ │ ┃\n' +
// '┃ isnumeric() │ ✓ │ ✓ │ ✓ │ │ ┃\n' +
// '┃ isdigit() │ ✓ │ ✓ │ │ │ ┃\n' +
// '┃ isdecimal() │ ✓ │ │ │ │ ┃\n' +
// '┗━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛\n';
const DIAGRAM_4_A =
"+--------------+----------------+----------------+----------------+----------------+\n" +
"| | {<float>} | {<float>:f} | {<float>:e} | {<float>:%} |\n" +
@ -199,6 +230,19 @@ const DIAGRAM_6_B =
'┃ count() │ │ │ │ ✓ ┃\n' +
'┗━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━┛\n';
// const DIAGRAM_6_B =
// '┏━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┓\n' +
// '┃ │ abc.Sequence │ Sequence │ Collection │ Iterable ┃\n' +
// '┠────────────┼──────────────┼────────────┼────────────┼────────────┨\n' +
// '┃ iter() │ ✓ │ ✓ │ ! │ ! ┃\n' +
// '┃ contains() │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
// '┃ len() │ ! │ ! │ ! │ ┃\n' +
// '┃ getitem() │ ! │ ! │ │ ┃\n' +
// '┃ reversed() │ ✓ │ ✓ │ │ ┃\n' +
// '┃ index() │ ✓ │ │ │ ┃\n' +
// '┃ count() │ ✓ │ │ │ ┃\n' +
// '┗━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┛\n';
const DIAGRAM_7_A =
'BaseException\n' +
' +-- SystemExit';

Loading…
Cancel
Save