June 2019
Beginner to intermediate
770 pages
19h 24m
English
Given a definition of a total for a Hand object, we can meaningfully define comparisons between Hand instances and comparisons between Hand and int. In order to determine which kind of comparison we're doing, we're forced to use isinstance().
The following is a partial definition of Hand with comparisons. Here's the first part:
class Hand: def __init__(self, dealer_card: Card2, *cards: Card2) -> None: self.dealer_card = dealer_card self.cards = list(cards) def __str__(self) -> str: return ", ".join(map(str, self.cards)) def __repr__(self) -> str: cards_text = ", ".join(map(repr, self.cards)) return f"{self.__class__.__name__}({self.dealer_card!r}, {cards_text})"
Here's the second part, emphasizing the comparison ...
Read now
Unlock full access