card

a simple API for creating and using playing cards

We’ll be using numbers to represent ranks. Those are ranks:

ranks
[None, 'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']

For instance, ranks at index 1

ranks[1]
'A'
suits
['diamond', 'spade', 'heard', 'club']

For instance, suits at index 0

suits[0]
'diamond'

Here’s an example of creating and displaying a card:

c = Card(suit=1,rank=3)
print(c)
3spade

source

Card

 Card (suit:int, rank:int)

A playing card

Type Details
suit int An index into suits
rank int An index into ranks

Comparison operators

Equality, less than, and greater than work on the rank and suit indices:

There are some instances:

test_eq(Card(suit=1,rank=3),Card(suit=1,rank=3))
test_ne(Card(suit=2,rank=3),Card(suit=1,rank=3))
assert Card(suit=1,rank=3)<Card(suit=2,rank=3)
assert Card(suit=3,rank=3)>Card(suit=2,rank=3)
assert not Card(suit=1,rank=3)>Card(suit=2,rank=3)