card — a basic playing card

A simple API for creating and using playing cards

Using numbers to represent cards and ranks

print(suits)
['♣️', '♦️', '♥️', '♠️']

For instance the suit at index (0)

suits[0]
'♣️'

These are the ranks

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

source

Card

 Card (suit:int, rank:int)

A playing card created by passing in rank from ranks and suit from suits

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

An example of creating and displaying a card

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

Comparison operators

Equality tests on the rank and suit indices

For example, here is a test for equality

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

A test of < and >

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