Browse Source

Comparable

pull/10/head
Jure Šorn 6 years ago
parent
commit
4ca2751f55
1 changed files with 15 additions and 1 deletions
  1. 16
      README.md

16
README.md

@ -635,9 +635,23 @@ class Employee(Person):
self.staff_num = staff_num
```
### Comparable
```python
class MyComparable:
def __init__(self, a):
self.a = a
def __eq__(self, other):
# If not defined it returns id(self) == id(other).
if isinstance(other, MyComparable):
return self.a == other.a
return False
def __hash__(self):
return hash(self.a)
```
### Sequence
```python
class <name>:
class MySequence:
def __init__(self, seq):
self.seq = seq
def __len__(self):

Loading…
Cancel
Save