|
226 | 226 |
|
227 | 227 | <body>
|
228 | 228 | <header>
|
229 |
| - <aside>October 30, 2021</aside> |
| 229 | + <aside>November 16, 2021</aside> |
230 | 230 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
|
231 | 231 | </header>
|
232 | 232 |
|
|
253 | 253 | main()
|
254 | 254 | </code></pre></div>
|
255 | 255 |
|
256 |
| -<div><h2 id="list"><a href="#list" name="list">#</a>List</h2><pre><code class="python language-python hljs"><list> = <list>[from_inclusive : to_exclusive : ±step_size] |
| 256 | +<div><h2 id="list"><a href="#list" name="list">#</a>List</h2><pre><code class="python language-python hljs"><list> = <list>[<slice>] <span class="hljs-comment"># Or: <list>[from_inclusive : to_exclusive : ±step]</span> |
257 | 257 | </code></pre></div>
|
258 | 258 |
|
259 | 259 | <pre><code class="python language-python hljs"><list>.append(<el>) <span class="hljs-comment"># Or: <list> += [<el>]</span>
|
260 | 260 | <list>.extend(<collection>) <span class="hljs-comment"># Or: <list> += <collection></span>
|
261 | 261 | </code></pre>
|
262 |
| -<pre><code class="python language-python hljs"><list>.sort() |
263 |
| -<list>.reverse() |
264 |
| -<list> = sorted(<collection>) |
265 |
| -<iter> = reversed(<list>) |
| 262 | +<pre><code class="python language-python hljs"><list>.sort() <span class="hljs-comment"># Sorts in ascending order.</span> |
| 263 | +<list>.reverse() <span class="hljs-comment"># Reverses the list in-place.</span> |
| 264 | +<list> = sorted(<collection>) <span class="hljs-comment"># Returns a new sorted list.</span> |
| 265 | +<iter> = reversed(<list>) <span class="hljs-comment"># Returns reversed iterator.</span> |
266 | 266 | </code></pre>
|
267 | 267 | <pre><code class="python language-python hljs">sum_of_elements = sum(<collection>)
|
268 | 268 | elementwise_sum = [sum(pair) <span class="hljs-keyword">for</span> pair <span class="hljs-keyword">in</span> zip(list_a, list_b)]
|
|
723 | 723 | <float> = <DTa>.timestamp() <span class="hljs-comment"># Seconds since the Epoch, from DTa.</span>
|
724 | 724 | </code></pre></div>
|
725 | 725 |
|
726 |
| -<div><h3 id="format-1">Format</h3><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime |
727 |
| -<span class="hljs-meta">>>> </span>dt = datetime.strptime(<span class="hljs-string">'2015-05-14 23:39:00.00 +0200'</span>, <span class="hljs-string">'%Y-%m-%d %H:%M:%S.%f %z'</span>) |
| 726 | +<div><h3 id="format-1">Format</h3><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span>dt = datetime.strptime(<span class="hljs-string">'2015-05-14 23:39:00.00 +0200'</span>, <span class="hljs-string">'%Y-%m-%d %H:%M:%S.%f %z'</span>) |
728 | 727 | <span class="hljs-meta">>>> </span>dt.strftime(<span class="hljs-string">"%A, %dth of %B '%y, %I:%M%p %Z"</span>)
|
729 | 728 | <span class="hljs-string">"Thursday, 14th of May '15, 11:39PM UTC+02:00"</span>
|
730 | 729 | </code></pre></div>
|
|
733 | 732 | <li><strong><code class="python hljs"><span class="hljs-string">'%Z'</span></code> only accepts <code class="python hljs"><span class="hljs-string">'UTC/GMT'</span></code> and local timezone's code. <code class="python hljs"><span class="hljs-string">'%z'</span></code> also accepts <code class="python hljs"><span class="hljs-string">'±HH:MM'</span></code>.</strong></li>
|
734 | 733 | <li><strong>For abbreviated weekday and month use <code class="python hljs"><span class="hljs-string">'%a'</span></code> and <code class="python hljs"><span class="hljs-string">'%b'</span></code>.</strong></li>
|
735 | 734 | </ul>
|
736 |
| -<div><h3 id="arithmetics">Arithmetics</h3><pre><code class="python language-python apache hljs"><D/DT> = <D/DT> ± <TD> <span class="hljs-comment"># Returned datetime can fall into missing hour.</span> |
737 |
| -<TD> = <D/DTn> - <D/DTn> <span class="hljs-comment"># Returns the difference, ignoring time jumps.</span> |
738 |
| -<TD> = <DTa> - <DTa> <span class="hljs-comment"># Ignores time jumps if they share tzinfo object.</span> |
739 |
| -<TD> = <DT_UTC> - <DT_UTC> <span class="hljs-comment"># Convert DTs to UTC to get the actual delta.</span> |
| 735 | +<div><h3 id="arithmetics">Arithmetics</h3><pre><code class="python language-python apache hljs"><D/DT> = <D/DT> ± <TD> <span class="hljs-comment"># Returned datetime can fall into missing hour.</span> |
| 736 | +<TD> = <D/DTn> - <D/DTn> <span class="hljs-comment"># Returns the difference, ignoring time jumps.</span> |
| 737 | +<TD> = <DTa> - <DTa> <span class="hljs-comment"># Ignores time jumps if they share tzinfo object.</span> |
| 738 | +<TD> = <TD> * <real> <span class="hljs-comment"># Also: <TD> = abs(<TD>) and <TD> = <TD> ±% <TD></span> |
| 739 | +<float> = <TD> / <TD> <span class="hljs-comment"># How many weeks/years there are in TD. Also '//'.</span> |
740 | 740 | </code></pre></div>
|
741 | 741 |
|
742 | 742 | <div><h2 id="arguments"><a href="#arguments" name="arguments">#</a>Arguments</h2><div><h3 id="insidefunctioncall">Inside Function Call</h3><pre><code class="python language-python hljs"><function>(<positional_args>) <span class="hljs-comment"># f(0, 0)</span>
|
|
3020 | 3020 |
|
3021 | 3021 |
|
3022 | 3022 | <footer>
|
3023 |
| - <aside>October 30, 2021</aside> |
| 3023 | + <aside>November 16, 2021</aside> |
3024 | 3024 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
|
3025 | 3025 | </footer>
|
3026 | 3026 |
|
|
0 commit comments