|
827 | 827 | <li><strong>If only repr() is defined, it will also be used for str().</strong></li>
|
828 | 828 | <li><strong>Methods decorated with <code class="python hljs"><span class="hljs-string">'@staticmethod'</span></code> do not receive 'self' nor 'cls' as their first arg.</strong></li>
|
829 | 829 | </ul>
|
830 |
| -<div><h4 id="strusecases">Str() use cases:</h4><pre><code class="python language-python hljs">print(<el>) |
| 830 | +<div><h4 id="expressionsthatcallthestrmethod">Expressions that call the str() method:</h4><pre><code class="python language-python hljs">print(<el>) |
831 | 831 | <span class="hljs-string">f'<span class="hljs-subst">{<el>}</span>'</span>
|
832 | 832 | logging.warning(<el>)
|
833 | 833 | csv.writer(<file>).writerow([<el>])
|
834 | 834 | <span class="hljs-keyword">raise</span> Exception(<el>)
|
835 | 835 | </code></pre></div>
|
836 | 836 |
|
837 |
| -<div><h4 id="reprusecases">Repr() use cases:</h4><pre><code class="python language-python hljs">print/str/repr([<el>]) |
| 837 | +<div><h4 id="expressionsthatcallthereprmethod">Expressions that call the repr() method:</h4><pre><code class="python language-python hljs">print/str/repr([<el>]) |
838 | 838 | <span class="hljs-string">f'<span class="hljs-subst">{<el>!r}</span>'</span>
|
839 | 839 | Z = dataclasses.make_dataclass(<span class="hljs-string">'Z'</span>, [<span class="hljs-string">'a'</span>]); print/str/repr(Z(<el>))
|
840 | 840 | <span class="hljs-meta">>>> </span><el>
|
|
1080 | 1080 | <li><strong>Only required methods are len() and getitem().</strong></li>
|
1081 | 1081 | <li><strong>Getitem() should return an item at the passed index or raise IndexError.</strong></li>
|
1082 | 1082 | <li><strong>Iter() and contains() automatically work on any object that has getitem() defined.</strong></li>
|
1083 |
| -<li><strong>Reversed() automatically works on any object that has len() and getitem() defined.</strong></li> |
| 1083 | +<li><strong>Reversed() automatically works on any object that has getitem() and len() defined.</strong></li> |
1084 | 1084 | </ul><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MySequence</span>:</span>
|
1085 | 1085 | <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, a)</span>:</span>
|
1086 | 1086 | self.a = a
|
|
0 commit comments