Browse Source

Comparable

pull/31/head
Jure Šorn 5 years ago
parent
commit
fefd403fc3
2 changed files with 4 additions and 4 deletions
  1. 4
      README.md
  2. 4
      index.html

4
README.md

@ -876,7 +876,7 @@ class MyComparable:
def __eq__(self, other):
if isinstance(other, type(self)):
return self.a == other.a
return False
return NotImplemented
```
### Hashable
@ -894,7 +894,7 @@ class MyHashable:
def __eq__(self, other):
if isinstance(other, type(self)):
return self.a == other.a
return False
return NotImplemented
def __hash__(self):
return hash(self.a)
```

4
index.html

@ -782,7 +782,7 @@ creature = Creature()
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__eq__</span><span class="hljs-params">(self, other)</span>:</span>
<span class="hljs-keyword">if</span> isinstance(other, type(self)):
<span class="hljs-keyword">return</span> self.a == other.a
<span class="hljs-keyword">return</span> <span class="hljs-keyword">False</span>
<span class="hljs-keyword">return</span> <span class="hljs-built_in">NotImplemented</span>
</code></pre>
<h3 id="hashable">Hashable</h3>
<ul>
@ -799,7 +799,7 @@ creature = Creature()
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__eq__</span><span class="hljs-params">(self, other)</span>:</span>
<span class="hljs-keyword">if</span> isinstance(other, type(self)):
<span class="hljs-keyword">return</span> self.a == other.a
<span class="hljs-keyword">return</span> <span class="hljs-keyword">False</span>
<span class="hljs-keyword">return</span> <span class="hljs-built_in">NotImplemented</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__hash__</span><span class="hljs-params">(self)</span>:</span>
<span class="hljs-keyword">return</span> hash(self.a)
</code></pre>

Loading…
Cancel
Save