card – A playing card

API for playing cards

We will be using numbers to represent playing card suits and ranks. The suits are:

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

For instance the suit at index 0 is:

suits[0]

The ranks are:

ranks

For instance the rank at index 1 (note that there is not aplyaing card at position 0, since we want the ranks to match the indices where possible):

ranks[14]

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 is an example creating an displaying card:

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

Comparison operators

Equality between two card is given by same suit and rank


source

Card.__eq__

 Card.__eq__ (other:__main__.Card)

Return self==value.

Card(suit=1, rank=1) == Card(suit=1, rank=1)
Card(suit=1, rank=1) == Card(suit=2, rank=1)
# Example
Card(suit=1, rank=1) < Card(suit=2, rank=2)

source

Card.__lt__

 Card.__lt__ (other:__main__.Card)

Return self<value.

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

source

Card.__gt__

 Card.__gt__ (other:__main__.Card)

Return self>value.