@@ -380,26 +380,26 @@ <h3 id="abc">ABC</h3>
380380< span class ="hljs-meta "> >>> </ span > isinstance([< span class ="hljs-number "> 1</ span > , < span class ="hljs-number "> 2</ span > , < span class ="hljs-number "> 3</ span > ], Iterable)
381381< span class ="hljs-keyword "> True</ span >
382382</ code > </ pre >
383- < pre > < code class ="text language-text "> ┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━┓
384- ┃ │ Sequence │ Collection │ Iterable ┃
385- ┠──────────────────┼──────────┼────────────┼──────────┨
386- ┃ list, range, str │ ✓ │ ✓ │ ✓ ┃
387- ┃ dict, set │ │ ✓ │ ✓ ┃
388- ┃ iter │ │ │ ✓ ┃
389- ┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┛
383+ < pre > < code class ="text language-text "> +------------------+----------+------------+----------+
384+ | | Sequence | Collection | Iterable |
385+ +------------------+----------+------------+----------+
386+ | list, range, str | yes | yes | yes |
387+ | dict, set | | yes | yes |
388+ | iter | | | yes |
389+ +------------------+----------+------------+----------+
390390</ code > </ pre >
391391< pre > < code class ="python language-python hljs "> < span class ="hljs-meta "> >>> </ span > < span class ="hljs-keyword "> from</ span > numbers < span class ="hljs-keyword "> import</ span > Integral, Rational, Real, Complex, Number
392392< span class ="hljs-meta "> >>> </ span > isinstance(< span class ="hljs-number "> 123</ span > , Number)
393393< span class ="hljs-keyword "> True</ span >
394394</ code > </ pre >
395- < pre > < code class ="text language-text "> ┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━┯━━━━━━━━━┯━━━━━━━━┓
396- ┃ │ Integral │ Rational │ Real │ Complex │ Number ┃
397- ┠────────────────────┼──────────┼──────────┼──────┼─────────┼────────┨
398- ┃ int │ ✓ │ ✓ │ ✓ │ ✓ │ ✓ ┃
399- ┃ fractions.Fraction │ │ ✓ │ ✓ │ ✓ │ ✓ ┃
400- ┃ float │ │ │ ✓ │ ✓ │ ✓ ┃
401- ┃ complex │ │ │ │ ✓ │ ✓ ┃
402- ┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━┷━━━━━━━━━┷━━━━━━━━┛
395+ < pre > < code class ="text language-text "> +--------------------+----------+----------+------+---------+--------+
396+ | | Integral | Rational | Real | Complex | Number |
397+ +--------------------+----------+----------+------+---------+--------+
398+ | int | yes | yes | yes | yes | yes |
399+ | fractions.Fraction | | yes | yes | yes | yes |
400+ | float | | | yes | yes | yes |
401+ | complex | | | | yes | yes |
402+ +--------------------+----------+----------+------+---------+--------+
403403</ code > </ pre >
404404< h2 id ="string "> < a href ="#string " name ="string "> #</ a > String</ h2 >
405405< pre > < code class ="python language-python hljs "> <str> = <str>.strip() < span class ="hljs-comment "> # Strips all whitespace characters from both ends.</ span >
@@ -509,31 +509,31 @@ <h3 id="floats">Floats</h3>
509509{< span class ="hljs-number "> 1.23456</ span > :< span class ="hljs-number "> 10.3</ span > %} < span class ="hljs-comment "> # ' 123.456%'</ span >
510510</ code > </ pre >
511511< h4 id ="comparisonoffloatpresentationtypes "> Comparison of float presentation types:</ h4 >
512- < pre > < code class ="text language-text "> ┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━┓
513- ┃ │ {<float>} │ {<float>:f} │ {<float>:e} │ {<float>:%} ┃
514- ┠────────────────┼────────────────┼───────────────┼────────────────┼─────────────────┨
515- ┃ 0.000056789 │ '5.6789e-05' │ '0.000057' │ '5.678900e-05' │ '0.005679%' ┃
516- ┃ 0.00056789 │ '0.00056789' │ '0.000568' │ '5.678900e-04' │ '0.056789%' ┃
517- ┃ 0.0056789 │ '0.0056789' │ '0.005679' │ '5.678900e-03' │ '0.567890%' ┃
518- ┃ 0.056789 │ '0.056789' │ '0.056789' │ '5.678900e-02' │ '5.678900%' ┃
519- ┃ 0.56789 │ '0.56789' │ '0.567890' │ '5.678900e-01' │ '56.789000%' ┃
520- ┃ 5.6789 │ '5.6789' │ '5.678900' │ '5.678900e+00' │ '567.890000%' ┃
521- ┃ 56.789 │ '56.789' │ '56.789000' │ '5.678900e+01' │ '5678.900000%' ┃
522- ┃ 567.89 │ '567.89' │ '567.890000' │ '5.678900e+02' │ '56789.000000%' ┃
523- ┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━┛
524- </ code > </ pre >
525- < pre > < code class ="text language-text "> ┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━┓
526- ┃ │ {<float>:.2} │ {<float>:.2f} │ {<float>:.2e} │ {<float>:.2%} ┃
527- ┠────────────────┼────────────────┼───────────────┼────────────────┼─────────────────┨
528- ┃ 0.000056789 │ '5.7e-05' │ '0.00' │ '5.68e-05' │ '0.01%' ┃
529- ┃ 0.00056789 │ '0.00057' │ '0.00' │ '5.68e-04' │ '0.06%' ┃
530- ┃ 0.0056789 │ '0.0057' │ '0.01' │ '5.68e-03' │ '0.57%' ┃
531- ┃ 0.056789 │ '0.057' │ '0.06' │ '5.68e-02' │ '5.68%' ┃
532- ┃ 0.56789 │ '0.57' │ '0.57' │ '5.68e-01' │ '56.79%' ┃
533- ┃ 5.6789 │ '5.7' │ '5.68' │ '5.68e+00' │ '567.89%' ┃
534- ┃ 56.789 │ '5.7e+01' │ '56.79' │ '5.68e+01' │ '5678.90%' ┃
535- ┃ 567.89 │ '5.7e+02' │ '567.89' │ '5.68e+02' │ '56789.00%' ┃
536- ┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━┛
512+ < pre > < code class ="text language-text "> +----------------+----------------+---------------+----------------+-----------------+
513+ | | {<float>} | {<float>:f} | {<float>:e} | {<float>:%} |
514+ +----------------+----------------+---------------+----------------+-----------------+
515+ | 0.000056789 | '5.6789e-05' | '0.000057' | '5.678900e-05' | '0.005679%' |
516+ | 0.00056789 | '0.00056789' | '0.000568' | '5.678900e-04' | '0.056789%' |
517+ | 0.0056789 | '0.0056789' | '0.005679' | '5.678900e-03' | '0.567890%' |
518+ | 0.056789 | '0.056789' | '0.056789' | '5.678900e-02' | '5.678900%' |
519+ | 0.56789 | '0.56789' | '0.567890' | '5.678900e-01' | '56.789000%' |
520+ | 5.6789 | '5.6789' | '5.678900' | '5.678900e+00' | '567.890000%' |
521+ | 56.789 | '56.789' | '56.789000' | '5.678900e+01' | '5678.900000%' |
522+ | 567.89 | '567.89' | '567.890000' | '5.678900e+02' | '56789.000000%' |
523+ +----------------+----------------+---------------+----------------+-----------------+
524+ </ code > </ pre >
525+ < pre > < code class ="text language-text "> +----------------+----------------+---------------+----------------+-----------------+
526+ | | {<float>:.2} | {<float>:.2f} | {<float>:.2e} | {<float>:.2%} |
527+ +----------------+----------------+---------------+----------------+-----------------+
528+ | 0.000056789 | '5.7e-05' | '0.00' | '5.68e-05' | '0.01%' |
529+ | 0.00056789 | '0.00057' | '0.00' | '5.68e-04' | '0.06%' |
530+ | 0.0056789 | '0.0057' | '0.01' | '5.68e-03' | '0.57%' |
531+ | 0.056789 | '0.057' | '0.06' | '5.68e-02' | '5.68%' |
532+ | 0.56789 | '0.57' | '0.57' | '5.68e-01' | '56.79%' |
533+ | 5.6789 | '5.7' | '5.68' | '5.68e+00' | '567.89%' |
534+ | 56.789 | '5.7e+01' | '56.79' | '5.68e+01' | '5678.90%' |
535+ | 567.89 | '5.7e+02' | '567.89' | '5.68e+02' | '56789.00%' |
536+ +----------------+----------------+---------------+----------------+-----------------+
537537</ code > </ pre >
538538< h3 id ="ints "> Ints</ h3 >
539539< pre > < code class ="python language-python hljs "> {< span class ="hljs-number "> 90</ span > :c} < span class ="hljs-comment "> # 'Z'</ span >
@@ -1153,18 +1153,18 @@ <h3 id="collectionsabcsequence">Collections.abc.Sequence</h3>
11531153 < span class ="hljs-keyword "> return</ span > self.a[i]
11541154</ code > </ pre >
11551155< h4 id ="tableofrequiredandavailablespecialmethods "> Table of required and available special methods:</ h4 >
1156- < pre > < code class ="text language-text "> ┏━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━━━┓
1157- ┃ │ Iterable │ Collection │ Sequence │ abc.Sequence ┃
1158- ┠────────────┼──────────┼────────────┼──────────┼──────────────┨
1159- ┃ iter() │ ! │ ! │ ✓ │ ✓ ┃
1160- ┃ contains() │ ✓ │ ✓ │ ✓ │ ✓ ┃
1161- ┃ len() │ │ ! │ ! │ ! ┃
1162- ┃ getitem() │ │ │ ! │ ! ┃
1163- ┃ reversed() │ │ │ ✓ │ ✓ ┃
1164- ┃ reverse() │ │ │ │ ✓ ┃
1165- ┃ index() │ │ │ │ ✓ ┃
1166- ┃ count() │ │ │ │ ✓ ┃
1167- ┗━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━━━┛
1156+ < pre > < code class ="text language-text "> +------------+----------+------------+----------+--------------+
1157+ | | Iterable | Collection | Sequence | abc.Sequence |
1158+ +------------+----------+------------+----------+--------------+
1159+ | iter() | REQ | REQ | yes | yes |
1160+ | contains() | yes | yes | yes | yes |
1161+ | len() | | REQ | REQ | REQ |
1162+ | getitem() | | | REQ | REQ |
1163+ | reversed() | | | yes | yes |
1164+ | reverse() | | | | yes |
1165+ | index() | | | | yes |
1166+ | count() | | | | yes |
1167+ +------------+----------+------------+----------+--------------+
11681168</ code > </ pre >
11691169< ul >
11701170< li > < strong > Other useful ABCs that automatically generate missing methods are: MutableSequence, Set, MutableSet, Mapping and MutableMapping.</ strong > </ li >
@@ -1633,29 +1633,29 @@ <h3 id="typediagram">Type Diagram</h3>
16331633< pre > < code class ="python language-python hljs "> type(MyClass) == MyMetaClass < span class ="hljs-comment "> # MyClass is an instance of MyMetaClass.</ span >
16341634type(MyMetaClass) == type < span class ="hljs-comment "> # MyMetaClass is an instance of type.</ span >
16351635</ code > </ pre >
1636- < pre > < code class ="text language-text "> ┏━━━━━━━━━┯━━━━━━━━━━━━━┓
1637- ┃ Classes │ Metaclasses ┃
1638- ┠─────────┼─────────────┨
1639- ┃ MyClass → MyMetaClass ┃
1640- ┃ │ ↓ ┃
1641- ┃ object ───→ type ←╮ ┃
1642- ┃ │ ↑ ╰───╯ ┃
1643- ┃ str ───────╯ ┃
1644- ┗━━━━━━━━━┷━━━━━━━━━━━━━┛
1636+ < pre > < code class ="text language-text "> +---------+-------------+
1637+ | Classes | Metaclasses |
1638+ +---------+-------------|
1639+ | MyClass > MyMetaClass |
1640+ | | v |
1641+ | object ---> type <+ |
1642+ | | ^ +---+ |
1643+ | str -------+ |
1644+ +---------+-------------+
16451645</ code > </ pre >
16461646< h3 id ="inheritancediagram "> Inheritance Diagram</ h3 >
16471647< pre > < code class ="python language-python hljs "> MyClass.__base__ == object < span class ="hljs-comment "> # MyClass is a subclass of object.</ span >
16481648MyMetaClass.__base__ == type < span class ="hljs-comment "> # MyMetaClass is a subclass of type.</ span >
16491649</ code > </ pre >
1650- < pre > < code class ="text language-text "> ┏━━━━━━━━━┯━━━━━━━━━━━━━┓
1651- ┃ Classes │ Metaclasses ┃
1652- ┠─────────┼─────────────┨
1653- ┃ MyClass │ MyMetaClass ┃
1654- ┃ ↓ │ ↓ ┃
1655- ┃ object ←─── type ┃
1656- ┃ ↑ │ ┃
1657- ┃ str │ ┃
1658- ┗━━━━━━━━━┷━━━━━━━━━━━━━┛
1650+ < pre > < code class ="text language-text "> +---------+-------------+
1651+ | Classes | Metaclasses |
1652+ +---------+-------------|
1653+ | MyClass | MyMetaClass |
1654+ | v | v |
1655+ | object <--- type |
1656+ | ^ | |
1657+ | str | |
1658+ +---------+-------------+
16591659</ code > </ pre >
16601660< h2 id ="operator "> < a href ="#operator " name ="operator "> #</ a > Operator</ h2 >
16611661< pre > < code class ="python language-python hljs "> < span class ="hljs-keyword "> from</ span > operator < span class ="hljs-keyword "> import</ span > add, sub, mul, truediv, floordiv, mod, pow, neg, abs
0 commit comments