|
56 | 56 |
|
57 | 57 | <body> |
58 | 58 | <header> |
59 | | - <aside>March 30, 2025</aside> |
| 59 | + <aside>April 1, 2025</aside> |
60 | 60 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
61 | 61 | </header> |
62 | 62 |
|
|
356 | 356 | <li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.IGNORECASE'</span></code> can be used with all functions.</strong></li> |
357 | 357 | <li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.MULTILINE'</span></code> makes <code class="python hljs"><span class="hljs-string">'^'</span></code> and <code class="python hljs"><span class="hljs-string">'$'</span></code> match the start/end of each line.</strong></li> |
358 | 358 | <li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.DOTALL'</span></code> makes <code class="python hljs"><span class="hljs-string">'.'</span></code> also accept the <code class="python hljs"><span class="hljs-string">'\n'</span></code>.</strong></li> |
359 | | -<li><strong><code class="python hljs"><span class="hljs-string">'re.compile(<regex>)'</span></code> returns a Pattern object with methods sub(), findall(), …</strong></li> |
| 359 | +<li><strong><code class="python hljs"><span class="hljs-string">'re.compile(<regex>)'</span></code> returns a Pattern object with methods sub(), findall(), etc.</strong></li> |
360 | 360 | </ul> |
361 | 361 | <div><h3 id="matchobject">Match Object</h3><pre><code class="python language-python hljs"><str> = <Match>.group() <span class="hljs-comment"># Returns the whole match. Also group(0).</span> |
362 | 362 | <str> = <Match>.group(<span class="hljs-number">1</span>) <span class="hljs-comment"># Returns part inside the first brackets.</span> |
|
463 | 463 | </code></pre></div> |
464 | 464 |
|
465 | 465 | <ul> |
466 | | -<li><strong>Decimal numbers are stored exactly, unlike most floats where: <code class="python hljs"><span class="hljs-string">'1.1 + 2.2 != 3.3'</span></code>.</strong></li> |
| 466 | +<li><strong>Decimal numbers are stored exactly, unlike most floats where <code class="python hljs"><span class="hljs-string">'1.1 + 2.2 != 3.3'</span></code>.</strong></li> |
467 | 467 | <li><strong>Floats can be compared with: <code class="python hljs"><span class="hljs-string">'math.isclose(<float>, <float>)'</span></code>.</strong></li> |
468 | 468 | <li><strong>Precision of decimal operations is set with: <code class="python hljs"><span class="hljs-string">'decimal.getcontext().prec = <int>'</span></code>.</strong></li> |
469 | 469 | <li><strong>Bools can be used anywhere ints can, because bool is a subclass of int: <code class="python hljs"><span class="hljs-string">'True + 1 == 2'</span></code>.</strong></li> |
|
585 | 585 | </code></pre></div> |
586 | 586 |
|
587 | 587 | <ul> |
588 | | -<li><strong><code class="python hljs"><span class="hljs-string">'%z'</span></code> accepts <code class="python hljs"><span class="hljs-string">'±HH[:]MM'</span></code> and returns <code class="python hljs"><span class="hljs-string">'±HHMM'</span></code> or empty string if datetime is naive.</strong></li> |
589 | | -<li><strong><code class="python hljs"><span class="hljs-string">'%Z'</span></code> accepts <code class="python hljs"><span class="hljs-string">'UTC/GMT'</span></code> and local timezone's code and returns timezone's name, <code class="python hljs"><span class="hljs-string">'UTC[±HH:MM]'</span></code> if timezone is nameless, or an empty string if datetime is naive.</strong></li> |
| 588 | +<li><strong><code class="python hljs"><span class="hljs-string">'%z'</span></code> accepts <code class="python hljs"><span class="hljs-string">'±HH[:]MM'</span></code> and returns <code class="python hljs"><span class="hljs-string">'±HHMM'</span></code> or empty string if object is naive.</strong></li> |
| 589 | +<li><strong><code class="python hljs"><span class="hljs-string">'%Z'</span></code> accepts <code class="python hljs"><span class="hljs-string">'UTC/GMT'</span></code> and local timezone's code and returns timezone's name, <code class="python hljs"><span class="hljs-string">'UTC[±HH:MM]'</span></code> if timezone is nameless, or an empty string if object is naive.</strong></li> |
590 | 590 | </ul> |
591 | 591 | <div><h3 id="arithmetics">Arithmetics</h3><pre><code class="python language-python apache hljs"><bool> = <D/T/DTn> > <D/T/DTn> <span class="hljs-comment"># Ignores time jumps (fold attribute). Also ==.</span> |
592 | 592 | <bool> = <DTa> > <DTa> <span class="hljs-comment"># Ignores time jumps if they share tzinfo object.</span> |
|
605 | 605 |
|
606 | 606 | <ul> |
607 | 607 | <li><strong>Function returns None if it doesn't encounter <code class="python hljs"><span class="hljs-string">'return <obj/exp>'</span></code> statement.</strong></li> |
608 | | -<li><strong>Before modifying a global variable from within the function run <code class="python hljs"><span class="hljs-string">'global <var_name>'</span></code>.</strong></li> |
| 608 | +<li><strong>Run <code class="python hljs"><span class="hljs-string">'global <var_name>'</span></code> inside the function before assigning to global variable.</strong></li> |
609 | 609 | <li><strong>Default values are evaluated when function is first encountered in the scope. Any mutation of a mutable default value will persist between invocations!</strong></li> |
610 | 610 | </ul> |
611 | 611 | <div><h3 id="functioncall">Function Call</h3><pre><code class="python language-python hljs"><obj> = <function>(<positional_args>) <span class="hljs-comment"># E.g. `func(0, 0)`.</span> |
@@ -2944,7 +2944,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment |
2944 | 2944 |
|
2945 | 2945 |
|
2946 | 2946 | <footer> |
2947 | | - <aside>March 30, 2025</aside> |
| 2947 | + <aside>April 1, 2025</aside> |
2948 | 2948 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a> |
2949 | 2949 | </footer> |
2950 | 2950 |
|
|
0 commit comments