Skip to content

Commit 4ca2751

Browse files
committed
Comparable
1 parent a6dac8d commit 4ca2751

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,23 @@ class Employee(Person):
635635
self.staff_num = staff_num
636636
```
637637

638+
### Comparable
639+
```python
640+
class MyComparable:
641+
def __init__(self, a):
642+
self.a = a
643+
def __eq__(self, other):
644+
# If not defined it returns id(self) == id(other).
645+
if isinstance(other, MyComparable):
646+
return self.a == other.a
647+
return False
648+
def __hash__(self):
649+
return hash(self.a)
650+
```
651+
638652
### Sequence
639653
```python
640-
class <name>:
654+
class MySequence:
641655
def __init__(self, seq):
642656
self.seq = seq
643657
def __len__(self):

0 commit comments

Comments
 (0)