deck

A deck of playing cards

source

Deck

 Deck ()

A deck of 52 cards not including jockers

When we initially create a deck, all 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, ♠

That should be 52 cards:

test_eq(len(deck), 52)

As a reminder, these are the suits that we defined for a Card:

suits
['♣', '♦', '♥', '♠']

We can check, say, if the Ace of Clubs is in the deck:

Card(1,1) in deck
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
deck = Deck()
test_eq(deck.pop(), Card(3,13))   # The K "\u2660"
test_eq(len(deck), 51)

source

Deck.remove

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

Removes cards from the deck or raises exception if it is not there

Type Details
card Card Card to remove
card23 = Card(2,3)
deck.remove(card23)

assert card23 not in deck

source

draw_n

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

Draw n cards, with replacement iif replace

Type Default Details
n int number of cards to draw
replace bool True whether or not draw with replacement
Card??
Init signature: Card(suit: int, rank: int)
Source:        
class Card:
    "A playing card"
    def __init__(self, 
                 suit: int, # An index into suits
                 rank: int  # An index into ranks
                 ):
        self.suit = suit
        self.rank = rank

    def __str__(self):
        return f"{ranks[self.rank]}, {suits[self.suit]}"
    
    __repr__ = __str__
File:           ~/Projects/GitHub/nbdev_cards/nbdev_cards/card.py
Type:           type
Subclasses: