June 2019
Beginner to intermediate
770 pages
19h 24m
English
This example will continue using the Cards class. The idea of mutable cards is strange, perhaps even wrong. However, we'd like to apply just one small tweak to the previous examples.
The following is a class hierarchy that provides us with the definitions of __hash__() and __eq__(), appropriate for mutable objects. The parent class is as follows:
class Card3: 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: ...
Read now
Unlock full access