June 2019
Beginner to intermediate
770 pages
19h 24m
English
Ideally, the __init__() initializer method will create a complete instance of an object. This is a bit more complex when creating a complete instance of a container that contains an internal collection of other objects. It'll be helpful if we can build this composite in a single step.
It's common to have both a method to incrementally accrete items, as well as the initializer special method, which can load all of the items in one step.
For example, we might have a class such as the following code snippet:
class Hand2: def __init__(self, dealer_card: Card, *cards: Card) -> None: self.dealer_card = dealer_card self.cards = list(cards) def card_append(self, card: Card) -> None: self.cards.append(card) ...
Read now
Unlock full access