|
483 | 483 | <div><h3 id="specialsequences">Special Sequences</h3><ul>
|
484 | 484 | <li><strong>By default digits, whitespaces and alphanumerics from all alphabets are matched, unless <code class="python hljs"><span class="hljs-string">'flags=re.ASCII'</span></code> argument is used.</strong></li>
|
485 | 485 | <li><strong>Use capital letter for negation.</strong></li>
|
486 |
| -</ul><pre><code class="python language-python hljs"><span class="hljs-string">'\d'</span> == <span class="hljs-string">'[0-9]'</span> <span class="hljs-comment"># Digit</span> |
487 |
| -<span class="hljs-string">'\s'</span> == <span class="hljs-string">'[ \t\n\r\f\v]'</span> <span class="hljs-comment"># Whitespace</span> |
488 |
| -<span class="hljs-string">'\w'</span> == <span class="hljs-string">'[a-zA-Z0-9_]'</span> <span class="hljs-comment"># Alphanumeric</span> |
| 486 | +</ul><pre><code class="python language-python hljs"><span class="hljs-string">'\d'</span> == <span class="hljs-string">'[0-9]'</span> <span class="hljs-comment"># Matches any digit.</span> |
| 487 | +<span class="hljs-string">'\s'</span> == <span class="hljs-string">'[ \t\n\r\f\v]'</span> <span class="hljs-comment"># Matches any whitespace.</span> |
| 488 | +<span class="hljs-string">'\w'</span> == <span class="hljs-string">'[a-zA-Z0-9_]'</span> <span class="hljs-comment"># Matches any alphanumeric.</span> |
489 | 489 | </code></pre></div>
|
490 | 490 |
|
491 | 491 |
|
|
1232 | 1232 | <li><strong>If there are no numeric values before auto(), it returns 1.</strong></li>
|
1233 | 1233 | <li><strong>Otherwise it returns an increment of the last numeric value.</strong></li>
|
1234 | 1234 | </ul>
|
1235 |
| -<pre><code class="python language-python hljs"><member> = <enum>.<member_name> <span class="hljs-comment"># Returns a member.</span> |
1236 |
| -<member> = <enum>[<span class="hljs-string">'<member_name>'</span>] <span class="hljs-comment"># Returns a member or raises KeyError.</span> |
1237 |
| -<member> = <enum>(<value>) <span class="hljs-comment"># Returns a member or raises ValueError.</span> |
1238 |
| -name = <member>.name |
1239 |
| -value = <member>.value |
| 1235 | +<pre><code class="python language-python hljs"><member> = <enum>.<member_name> <span class="hljs-comment"># Returns a member.</span> |
| 1236 | +<member> = <enum>[<span class="hljs-string">'<member_name>'</span>] <span class="hljs-comment"># Returns a member or raises KeyError.</span> |
| 1237 | +<member> = <enum>(<value>) <span class="hljs-comment"># Returns a member or raises ValueError.</span> |
| 1238 | +<str> = <member>.name <span class="hljs-comment"># Returns member's name.</span> |
| 1239 | +<obj> = <member>.value <span class="hljs-comment"># Returns member's value.</span> |
1240 | 1240 | </code></pre>
|
1241 | 1241 | <pre><code class="python language-python hljs">list_of_members = list(<enum>)
|
1242 | 1242 | member_names = [a.name <span class="hljs-keyword">for</span> a <span class="hljs-keyword">in</span> <enum>]
|
|
1831 | 1831 | LogicOp = enum.Enum(<span class="hljs-string">'LogicOp'</span>, {<span class="hljs-string">'AND'</span>: op.and_, <span class="hljs-string">'OR'</span> : op.or_})
|
1832 | 1832 | last_el = op.methodcaller(<span class="hljs-string">'pop'</span>)(<list>)
|
1833 | 1833 | </code></pre>
|
1834 |
| -<div><h2 id="introspection"><a href="#introspection" name="introspection">#</a>Introspection</h2><p><strong>Inspecting code at runtime.</strong></p><div><h3 id="variables">Variables</h3><pre><code class="python language-python hljs"><list> = dir() <span class="hljs-comment"># Names of variables in current scope.</span> |
1835 |
| -<dict> = locals() <span class="hljs-comment"># Dict of local variables. Also vars().</span> |
1836 |
| -<dict> = globals() <span class="hljs-comment"># Dict of global variables.</span> |
| 1834 | +<div><h2 id="introspection"><a href="#introspection" name="introspection">#</a>Introspection</h2><p><strong>Inspecting code at runtime.</strong></p><div><h3 id="variables">Variables</h3><pre><code class="python language-python hljs"><list> = dir() <span class="hljs-comment"># Returns names of variables in current scope.</span> |
| 1835 | +<dict> = locals() <span class="hljs-comment"># Returns dict of local variables. Also vars().</span> |
| 1836 | +<dict> = globals() <span class="hljs-comment"># Returns dict of global variables.</span> |
1837 | 1837 | </code></pre></div></div>
|
1838 | 1838 |
|
1839 | 1839 |
|
|
1884 | 1884 | <pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span>MyClass.a, MyClass.b
|
1885 | 1885 | (<span class="hljs-string">'abcde'</span>, <span class="hljs-number">12345</span>)
|
1886 | 1886 | </code></pre>
|
1887 |
| -<div><h3 id="typediagram">Type Diagram</h3><pre><code class="python language-python hljs">type(MyClass) == MyMetaClass <span class="hljs-comment"># MyClass is an instance of MyMetaClass.</span> |
1888 |
| -type(MyMetaClass) == type <span class="hljs-comment"># MyMetaClass is an instance of type.</span> |
| 1887 | +<div><h3 id="typediagram">Type Diagram</h3><pre><code class="python language-python hljs">type(MyClass) == MyMetaClass <span class="hljs-comment"># MyClass is an instance of MyMetaClass.</span> |
| 1888 | +type(MyMetaClass) == type <span class="hljs-comment"># MyMetaClass is an instance of type.</span> |
1889 | 1889 | </code></pre></div>
|
1890 | 1890 |
|
1891 | 1891 | <pre><code class="text language-text">+-------------+-------------+
|
|
1898 | 1898 | | str ---------+ |
|
1899 | 1899 | +-------------+-------------+
|
1900 | 1900 | </code></pre>
|
1901 |
| -<div><h3 id="inheritancediagram">Inheritance Diagram</h3><pre><code class="python language-python hljs">MyClass.__base__ == object <span class="hljs-comment"># MyClass is a subclass of object.</span> |
1902 |
| -MyMetaClass.__base__ == type <span class="hljs-comment"># MyMetaClass is a subclass of type.</span> |
| 1901 | +<div><h3 id="inheritancediagram">Inheritance Diagram</h3><pre><code class="python language-python hljs">MyClass.__base__ == object <span class="hljs-comment"># MyClass is a subclass of object.</span> |
| 1902 | +MyMetaClass.__base__ == type <span class="hljs-comment"># MyMetaClass is a subclass of type.</span> |
1903 | 1903 | </code></pre></div>
|
1904 | 1904 |
|
1905 | 1905 | <pre><code class="text language-text">+-------------+-------------+
|
|
2197 | 2197 | <ul>
|
2198 | 2198 | <li><strong>If row and column indexes differ in shape, they are combined with broadcasting.</strong></li>
|
2199 | 2199 | </ul>
|
2200 |
| -<div><h3 id="broadcasting">Broadcasting</h3><p><strong>Broadcasting is a set of rules by which NumPy functions operate on arrays of different sizes and/or dimensions.</strong></p><pre><code class="python language-python hljs">left = [[<span class="hljs-number">0.1</span>], [<span class="hljs-number">0.6</span>], [<span class="hljs-number">0.8</span>]] <span class="hljs-comment"># Shape: (3, 1)</span> |
2201 |
| -right = [ <span class="hljs-number">0.1</span> , <span class="hljs-number">0.6</span> , <span class="hljs-number">0.8</span> ] <span class="hljs-comment"># Shape: (3)</span> |
| 2200 | +<div><h3 id="broadcasting">Broadcasting</h3><p><strong>Broadcasting is a set of rules by which NumPy functions operate on arrays of different sizes and/or dimensions.</strong></p><pre><code class="python language-python hljs">left = [[<span class="hljs-number">0.1</span>], [<span class="hljs-number">0.6</span>], [<span class="hljs-number">0.8</span>]] <span class="hljs-comment"># Shape: (3, 1)</span> |
| 2201 | +right = [ <span class="hljs-number">0.1</span> , <span class="hljs-number">0.6</span> , <span class="hljs-number">0.8</span> ] <span class="hljs-comment"># Shape: (3)</span> |
2202 | 2202 | </code></pre></div>
|
2203 | 2203 |
|
2204 | 2204 |
|
2205 |
| -<div><h4 id="1ifarrayshapesdifferinlengthleftpadtheshortershapewithones">1. If array shapes differ in length, left-pad the shorter shape with ones:</h4><pre><code class="python language-python hljs">left = [[<span class="hljs-number">0.1</span>], [<span class="hljs-number">0.6</span>], [<span class="hljs-number">0.8</span>]] <span class="hljs-comment"># Shape: (3, 1)</span> |
2206 |
| -right = [[<span class="hljs-number">0.1</span> , <span class="hljs-number">0.6</span> , <span class="hljs-number">0.8</span>]] <span class="hljs-comment"># Shape: (1, 3) <- !</span> |
| 2205 | +<div><h4 id="1ifarrayshapesdifferinlengthleftpadtheshortershapewithones">1. If array shapes differ in length, left-pad the shorter shape with ones:</h4><pre><code class="python language-python hljs">left = [[<span class="hljs-number">0.1</span>], [<span class="hljs-number">0.6</span>], [<span class="hljs-number">0.8</span>]] <span class="hljs-comment"># Shape: (3, 1)</span> |
| 2206 | +right = [[<span class="hljs-number">0.1</span> , <span class="hljs-number">0.6</span> , <span class="hljs-number">0.8</span>]] <span class="hljs-comment"># Shape: (1, 3) <- !</span> |
2207 | 2207 | </code></pre></div>
|
2208 | 2208 |
|
2209 | 2209 | <div><h4 id="2ifanydimensionsdifferinsizeexpandtheonesthathavesize1byduplicatingtheirelements">2. If any dimensions differ in size, expand the ones that have size 1 by duplicating their elements:</h4><pre><code class="python language-python hljs">left = [[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.1</span>, <span class="hljs-number">0.1</span>], [<span class="hljs-number">0.6</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.6</span>], [<span class="hljs-number">0.8</span>, <span class="hljs-number">0.8</span>, <span class="hljs-number">0.8</span>]] <span class="hljs-comment"># Shape: (3, 3) <- !</span>
|
|
0 commit comments