Jan-15-2018, 08:29 PM
Suppose I want to create a Card class for standard playing cards like this:
class Card: def __init__(self, description, strength): self.description = description # e.g. "Two of Clubs" self.strength = strength # e.g. 0 for Twos, 1 for Threes, etc def __repr__(self): return self.description # returns "Two of Clubs" rather than the bare objectAnd then I want to instantiate every Card in a standard deck. Here's the solution I have right now:
card1 = Card("Two of Clubs", 0) card2 = Card("Two of Spades", 0) ... card51 = Card("Ace of Hearts", 11) card52 = Card("Ace of Diamonds", 11)Is there an automated way to instantiate these objects? And is there an automated way to add them either to a collection representing a standard deck of playing cards, or a Deck class that can be used to instantiate various types of decks (including decks with multiple instances of one card, decks with cards removed, etc.)?