June 2019
Beginner to intermediate
770 pages
19h 24m
English
The following is a simple class hierarchy that provides us with definitions of __hash__() and __eq__():
import sysclass Card2: insure = False def __init__(self, rank: str, suit: "Suit", hard: int, soft: int) -> None: self.rank = rank self.suit = suit self.hard = hard self.soft = soft def __repr__(self) -> str: return f"{self.__class__.__name__}(suit={self.suit!r}, rank={self.rank!r})" def __str__(self) -> str: return f"{self.rank}{self.suit}" def __eq__(self, other: Any) -> bool: return ( self.suit == cast(Card2, other).suit and self.rank == cast(Card2, other).rank ) def __hash__(self) -> int: return (hash(self.suit) + 4*hash(self.rank)) % sys.hash_info.modulusclass AceCard2(Card2): insure =
Read now
Unlock full access