|
559 | 559 | | 567.89 | '5.7e+02' | '567.89' | '5.68e+02' | '56789.00%' |
|
560 | 560 | +---------------+-----------------+-----------------+-----------------+-----------------+
|
561 | 561 | </code></pre>
|
562 |
| -<div><h3 id="ints">Ints</h3><pre><code class="python language-python hljs">{<span class="hljs-number">90</span>:c} <span class="hljs-comment"># 'Z'</span> |
563 |
| -{<span class="hljs-number">90</span>:b} <span class="hljs-comment"># '1011010'</span> |
564 |
| -{<span class="hljs-number">90</span>:X} <span class="hljs-comment"># '5A'</span> |
| 562 | +<div><h3 id="ints">Ints</h3><pre><code class="python language-python hljs">{<span class="hljs-number">90</span>:c} <span class="hljs-comment"># 'Z'</span> |
| 563 | +{<span class="hljs-number">90</span>:b} <span class="hljs-comment"># '1011010'</span> |
| 564 | +{<span class="hljs-number">90</span>:X} <span class="hljs-comment"># '5A'</span> |
565 | 565 | </code></pre></div>
|
566 | 566 |
|
567 |
| -<div><h2 id="numbers"><a href="#numbers" name="numbers">#</a>Numbers</h2><div><h3 id="types">Types</h3><pre><code class="python language-python hljs"><int> = int(<float/str/bool>) <span class="hljs-comment"># Or: math.floor(<float>)</span> |
568 |
| -<float> = float(<int/str/bool>) <span class="hljs-comment"># Or: <real>e±<int></span> |
569 |
| -<complex> = complex(real=<span class="hljs-number">0</span>, imag=<span class="hljs-number">0</span>) <span class="hljs-comment"># Or: <real> ± <real>j</span> |
570 |
| -<Fraction> = fractions.Fraction(numerator=<span class="hljs-number">0</span>, denominator=<span class="hljs-number">1</span>) |
571 |
| -<Decimal> = decimal.Decimal(<str/int/float>) |
| 567 | +<div><h2 id="numbers"><a href="#numbers" name="numbers">#</a>Numbers</h2><div><h3 id="types">Types</h3><pre><code class="python language-python hljs"><int> = int(<float/str/bool>) <span class="hljs-comment"># Or: math.floor(<float>)</span> |
| 568 | +<float> = float(<int/str/bool>) <span class="hljs-comment"># Or: <real>e±<int></span> |
| 569 | +<complex> = complex(real=<span class="hljs-number">0</span>, imag=<span class="hljs-number">0</span>) <span class="hljs-comment"># Or: <real> ± <real>j</span> |
| 570 | +<Fraction> = fractions.Fraction(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>) <span class="hljs-comment"># Or: Fraction(numerator=0, denominator=1)</span> |
| 571 | +<Decimal> = decimal.Decimal(<str/int>) <span class="hljs-comment"># Or: Decimal((sign, digits, exponent))</span> |
572 | 572 | </code></pre></div></div>
|
573 | 573 |
|
574 | 574 |
|
|
577 | 577 | <li><strong>Decimal numbers can be represented exactly, unlike floats where <code class="python hljs"><span class="hljs-string">'1.1 + 2.2 != 3.3'</span></code>.</strong></li>
|
578 | 578 | <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>
|
579 | 579 | </ul>
|
580 |
| -<div><h3 id="basicfunctions">Basic Functions</h3><pre><code class="python language-python hljs"><num> = pow(<num>, <num>) <span class="hljs-comment"># Or: <num> ** <num></span> |
581 |
| -<num> = abs(<num>) <span class="hljs-comment"># <float> = abs(<complex>)</span> |
582 |
| -<num> = round(<num> [, ±ndigits]) <span class="hljs-comment"># `round(126, -1) == 130`</span> |
| 580 | +<div><h3 id="basicfunctions">Basic Functions</h3><pre><code class="python language-python hljs"><num> = pow(<num>, <num>) <span class="hljs-comment"># Or: <num> ** <num></span> |
| 581 | +<num> = abs(<num>) <span class="hljs-comment"># <float> = abs(<complex>)</span> |
| 582 | +<num> = round(<num> [, ±ndigits]) <span class="hljs-comment"># `round(126, -1) == 130`</span> |
583 | 583 | </code></pre></div>
|
584 | 584 |
|
585 | 585 | <div><h3 id="math">Math</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> math <span class="hljs-keyword">import</span> e, pi, inf, nan, isinf, isnan
|
|
597 | 597 | shuffle(<list>)
|
598 | 598 | </code></pre></div>
|
599 | 599 |
|
600 |
| -<div><h3 id="binhex">Bin, Hex</h3><pre><code class="python language-python hljs"><int> = <span class="hljs-number">0</span>b<bin> <span class="hljs-comment"># Or: 0x<hex></span> |
601 |
| -<int> = int(<span class="hljs-string">'<bin>'</span>, <span class="hljs-number">2</span>) <span class="hljs-comment"># Or: int('<hex>', 16)</span> |
602 |
| -<int> = int(<span class="hljs-string">'0b<bin>'</span>, <span class="hljs-number">0</span>) <span class="hljs-comment"># Or: int('0x<hex>', 0)</span> |
603 |
| -<span class="hljs-string">'0b<bin>'</span> = bin(<int>) <span class="hljs-comment"># Or: hex(<int>)</span> |
| 600 | +<div><h3 id="binhex">Bin, Hex</h3><pre><code class="python language-python hljs"><int> = <span class="hljs-number">0</span>b<bin> <span class="hljs-comment"># Or: 0x<hex></span> |
| 601 | +<int> = int(<span class="hljs-string">'<bin>'</span>, <span class="hljs-number">2</span>) <span class="hljs-comment"># Or: int('<hex>', 16)</span> |
| 602 | +<int> = int(<span class="hljs-string">'0b<bin>'</span>, <span class="hljs-number">0</span>) <span class="hljs-comment"># Or: int('0x<hex>', 0)</span> |
| 603 | +<span class="hljs-string">'0b<bin>'</span> = bin(<int>) <span class="hljs-comment"># Or: hex(<int>)</span> |
604 | 604 | </code></pre></div>
|
605 | 605 |
|
606 |
| -<div><h3 id="bitwiseoperators">Bitwise Operators</h3><pre><code class="python language-python hljs"><int> = <int> & <int> <span class="hljs-comment"># And</span> |
607 |
| -<int> = <int> | <int> <span class="hljs-comment"># Or</span> |
608 |
| -<int> = <int> ^ <int> <span class="hljs-comment"># Xor (0 if both bits equal)</span> |
609 |
| -<int> = <int> << n_bits <span class="hljs-comment"># Shift left</span> |
610 |
| -<int> = <int> >> n_bits <span class="hljs-comment"># Shift right</span> |
611 |
| -<int> = ~<int> <span class="hljs-comment"># Compliment (flips bits)</span> |
| 606 | +<div><h3 id="bitwiseoperators">Bitwise Operators</h3><pre><code class="python language-python hljs"><int> = <int> & <int> <span class="hljs-comment"># And</span> |
| 607 | +<int> = <int> | <int> <span class="hljs-comment"># Or</span> |
| 608 | +<int> = <int> ^ <int> <span class="hljs-comment"># Xor (0 if both bits equal)</span> |
| 609 | +<int> = <int> << n_bits <span class="hljs-comment"># Shift left</span> |
| 610 | +<int> = <int> >> n_bits <span class="hljs-comment"># Shift right</span> |
| 611 | +<int> = ~<int> <span class="hljs-comment"># Compliment (flips bits)</span> |
612 | 612 | </code></pre></div>
|
613 | 613 |
|
614 | 614 | <div><h2 id="combinatorics"><a href="#combinatorics" name="combinatorics">#</a>Combinatorics</h2><ul>
|
|
0 commit comments