Add answer (#136)

Co-authored-by: Vladimir <v@ao-sbk.ru>
This commit is contained in:
kratorr 2021-07-12 12:20:33 +03:00 committed by GitHub
parent e1379fb6b5
commit 4c6d7360ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8370,6 +8370,26 @@ a = f()
<details> <details>
<summary>You wrote a class to represent a car. How would you compare two cars instances if two cars are equal if they have the same model and color?</summary><br><b> <summary>You wrote a class to represent a car. How would you compare two cars instances if two cars are equal if they have the same model and color?</summary><br><b>
```
class Car:
def __init__(self, model, color):
self.model = model
self.color = color
def __eq__(self, other):
if not isinstance(other, Car):
return NotImplemented
return self.model == other.model and self.color == other.color
>> a = Car('model_1', 'red')
>> b = Car('model_2', 'green')
>> c = Car('model_1', 'red')
>> a == b
False
>> a == c
True
```
</b></details> </b></details>
<details> <details>