from nbdev.showdoc import *
from nbdev_project.card import Card
from fastcore.test import *Deck of cards
A deck of playing cards
Deck
Deck ()
Initialize self. See help(type(self)) for accurate signature.
Create a deck of card and check that there is 52 cards there.
deck = Deck()
test_eq(len(deck), 52)Card??Init signature: Card(suit: int, rank: int)
Source:
class Card:
"""A playing card, created by passing in rank from ranks and suit from suits"""
def __init__(self,
suit:int, # An index into suits
rank:int): # An index into ranks
self.suit = suit
self.rank = rank
def __str__(self):
return f"{ranks[self.rank]}{suits[self.suit]}"
def __eq__(self,a):
if isinstance(a,Card):
return (self.suit,self.rank) == (a.suit, a.rank)
else:
return False
__repr__ = __str__ # use the same formating as jupyter
File: ~/git/nbdev-project/nbdev_project/card.py
Type: type
Subclasses:
Deck.pop
Deck.pop ()
test_eq(deck.pop(), Card(3,13))