June 2019
Beginner to intermediate
770 pages
19h 24m
English
Let's see how default definitions operate. The following is a simple class hierarchy that uses the default definitions of __hash__() and __eq__():
class Card: 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}"class NumberCard(Card): def __init__(self, rank: int, suit: "Suit") -> None: super().__init__(str(rank), suit, rank, rank)class AceCard(Card): insure = True def __init__(self, rank: int, suit: "Suit") -> None: super().__init__ ...
Read now
Unlock full access