deck

A deck of playing cards

source

Deck

 Deck ()

A deck of 52 cards

When we initially create a deck, all of the cards will be present.

deck = Deck()
deck
A♣️; 2♣️; 3♣️; 4♣️; 5♣️; 6♣️; 7♣️; 8♣️; 9♣️; 10♣️; J♣️; Q♣️; K♣️; A♦️; 2♦️; 3♦️; 4♦️; 5♦️; 6♦️; 7♦️; 8♦️; 9♦️; 10♦️; J♦️; Q♦️; K♦️; A❤️; 2❤️; 3❤️; 4❤️; 5❤️; 6❤️; 7❤️; 8❤️; 9❤️; 10❤️; J❤️; Q❤️; K❤️; A♠️; 2♠️; 3♠️; 4♠️; 5♠️; 6♠️; 7♠️; 8♠️; 9♠️; 10♠️; J♠️; Q♠️; K♠️

There should be 52 cards.

test_eq(len(deck),52)

We can check if, say, the Ace of Hearts is in the deck.

assert Card(suit=2,rank=1) in deck

source

Deck.pop

 Deck.pop (idx:int=-1)

Remove one card from the deck

Type Default Details
idx int -1 The index of the card to remove, defaulting to the last one.
deck = Deck()
test_eq(deck.pop(),Card(3,13))

There are 51 cards left in the deck now

test_eq(len(deck), 51)

source

Deck.remove

 Deck.remove (card:taash.card.Card)

Removes card from the deck. Raises an exception if it is not there

deck = Deck()
card23 = Card(2,3)
deck.remove(card23)

assert card23 not in deck

source

Deck.shuffle

 Deck.shuffle ()

Shuffles the cards in the deck


source

draw_n

 draw_n (n:int, replace:bool=True)

Draw n cards, with replacement if replace

Type Default Details
n int number of cards to draw
replace bool True whether or not draw with replacement
draw_n(13, replace=False)
[10♦️, 3♠️, A♣️, 5♠️, 7❤️, 4♦️, Q♣️, K♦️, 6❤️, 9♠️, Q♠️, 8❤️, 2♣️]