June 2019
Beginner to intermediate
770 pages
19h 24m
English
In the previous examples, we defined the card property to deal additional cards into an object of the Hand class.
Since setter (and deleter) properties are created from the getter property, we must always define a getter property first using code that looks like the following example:
@propertydef card(self) -> List[BlackJackCard]: return self._cards@card.setterdef card(self, aCard: BlackJackCard) -> None: self._cards.append(aCard)@card.deleterdef card(self) -> None: self._cards.pop(-1)
This allows us to add a card to the hand with a simple statement like the following:
h.card = d.pop()
The preceding assignment statement has a disadvantage because it looks like it replaces all the cards with a single card. ...
Read now
Unlock full access