card–A basic playing card

A simple API for creating and using playing cards

The suits are displayed with a nice emoji

suits
['♣️', '♦️', '❤️', '♠️']

For instance the suit at index 0:

suits[0]
'♣️'

The ranks are mostly what one would expect. Note the None at index 0 this is because we want the rank of a valid card to match it’s index.

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

source

Card

 Card (suit:int, rank:int)

A playing card

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

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

c = Card(suit=1,rank=3)
c
3♦️
print(c)
3♦️

Comparison Operators

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

For instance, here is a test for equality

test_eq(Card(suit=1,rank=3), Card(suit=1,rank=3))

and a test for <

assert Card(suit=1,rank=3) < Card(suit=2,rank=3)

and finally for >

assert Card(suit=2,rank=3) > Card(suit=1,rank=3)