deck – A deck of playing cards

A collection of cards

source

Deck

 Deck ()

A deck of 52 cards


source

Deck.shuffle

 Deck.shuffle ()

Randomizes card order in deck

A new deck contains all the cards:

Examples

deck = Deck()
deck
♣️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; ♦️A

It contains 52 cards.

len(deck)
52
test_ne(len(deck), 51)

We can check if a specific cards (here Ace of Club) is in the deck.

print(Card(0,14))
Card(1,14) in deck
♣️A
True

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

Examples

Here we the Ace of Hearts from the deck!

deck = Deck()
ace_of_hearts = deck.pop(38)
ace_of_hearts
❤️A
# Tests
deck = Deck()
test_eq(Card(2,14), deck.pop(38))

source

Deck.remove

 Deck.remove (card:enough_cards.card.Card)
Type Details
card Card Card to remove

Examples

# Tests
deck = Deck()
remove_card = Card(2,14)
deck.remove(remove_card)
test_eq(51, len(deck))
test_ne(True, Card(2,14) in deck)
assert remove_card not in deck

source

Deck.draw

 Deck.draw (n:int=1, replace:bool=True)
Type Default Details
n int 1 Number of cards to be drawn
replace bool True When true: drawn with replace, if false: not.

Examples

# drawn without replacement
deck = Deck()
deck.draw(10, False)
[♣️A, ♠️A, ♦️J, ♣️4, ❤️2, ♦️4, ♦️10, ❤️K, ♠️3, ♦️6]
# drawn with replacement
deck.draw(10)
[♦️10, ❤️K, ♣️7, ♦️3, ♠️Q, ♠️K, ♠️K, ♠️10, ♣️J, ♦️J]