From 8d9e4b4cb8a7344f8d9e88ff7a9534315ad978b7 Mon Sep 17 00:00:00 2001 From: Mike Bloy Date: Sat, 28 Oct 2023 19:08:34 -0500 Subject: [PATCH] ex36 --- stock.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stock.py b/stock.py index 2bbc98c..c4881d5 100644 --- a/stock.py +++ b/stock.py @@ -7,6 +7,18 @@ class Stock: self.shares = shares self.price = price + def __repr__(self): + return f"Stock({self.name!r}, {self.shares!r}, {self.price!r})" + + def __eq__(self, other): + if not isinstance(other, Stock): + return False + return (self.name, self.shares, self.price) == ( + other.name, + other.shares, + other.price, + ) + @classmethod def from_row(cls, row): values = [func(val) for func, val in zip(cls._types, row)]