Welcome to Deck of Cards’s documentation!

Contents:

deck_of_cards package

Module contents

A Python Implementation Of A Deck of Cards

Submodules

deck_of_cards.card module

This module provides the Card object. This module also has 5 constant attributes that help validate or string format the Card object: POSSIBLE_SUIT, POSSIBLE_RANK, , JOKER_SUIT, JOKER_RANK, and RANK_TRANSLATION

class deck_of_cards.card.Card(rank, suit)[source]

Bases: object

A Card object

Parameters:
Raises:

ValueError

__eq__(other)[source]

Override equality method

Returns:True if two objects are cards and have the same _rank and _suit
Return type:bool
__ne__(other)[source]

Override inequality method

Returns:not __eq__
Return type:bool
__repr__()[source]

This method returns an unambigious string representation of the card object

Returns:unambigious string represenation of card object
Return type:str
__str__()[source]

This method returns a nice string representation of the card object

useful in printing card object as “%s”

Returns:human readable string represenation of card object
Return type:str
_rank = None

Holds an integer which represents the card rank

_suit = None

Holds the suit as a lowercase string

_translate_rank()[source]

This is a hidden method that changes the card rank to a human-readable string. It also returns the title case of the string if possible.

‘Ace’ for 1

‘Joker’ for joker

Returns:human-readable string for face cards or card rank
Return type:str
get_rank()[source]
Returns:_rank
Return type:int
get_suit()[source]
Returns:_suit
Return type:str
is_joker()[source]
Returns:True if joker
Return type:bool
deck_of_cards.card.JOKER_RANK = 0

a number representing the Joker’s rank

deck_of_cards.card.JOKER_SUIT = 'joker'

a string representing the Joker’s suit

deck_of_cards.card.POSSIBLE_RANK = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

an array with the possible ranks

deck_of_cards.card.POSSIBLE_SUIT = ['hearts', 'diamonds', 'spades', 'clubs']

an array with all the possible suit strings

deck_of_cards.card.RANK_TRANSLATION = {1: 'ace', 11: 'jack', 12: 'queen', 13: 'king'}

a dictionary which translates the special face cards to strings

deck_of_cards.deck module

This module provides the Deck object

class deck_of_cards.deck.Deck(with_jokers=True)[source]

Bases: object

A Deck object

A new deck starts out ordered.

If jokers are included, contains (2 + 4 * 13) deck_of_cards.card.Card objects

If no jokers are included, contains (4 * 13) deck_of_cards.card.Card objects

Parameters:with_jokers (bool) – include jokers if True
__repr__()[source]
Returns:unambigious string represenation of deck object
Return type:str
__str__()[source]
Returns:human readable string represenation of deck object
Return type:str
_cards = []

an array of unused deck_of_cards.card.Card objects that are waiting to be dealt

_discarded_cards = []

an array of discarded deck_of_cards.card.Card objects

_in_play_cards = []

an array of deck_of_cards.card.Card objects that have been dealt

_with_jokers = True

a boolean to represent if jokers exist in deck

check_deck()[source]

Check to make sure all the cards are accounted

Returns:True if all cards are accounted
Return type:bool
deal()[source]

Deals a single deck_of_cards.card.Card from _cards

Raises an IndexError when _cards is empty

Returns:a single deck_of_cards.card.Card
Return type:deck_of_cards.card.Card
Raises:IndexError
discard(cards)[source]

Remove cards from the _in_play_cards array and add them to _discarded_cards array

Raises a ValueError when trying to discard a card that does not exist in _in_play_cards.

Parameters:cards (array) – an array of deck_of_cards.card.Card objects or a single deck_of_cards.card.Card
Raises:ValueError
is_empty()[source]

This method returns true if the deck(_cards) is empty

Returns:True if deck is empty
Return type:bool
shuffle()[source]

Shuffle the unused set of cards in _cards

deck_of_cards.deck.LOGGER = <logging.Logger object>

a logger object

Indices and tables