Card Methods
Looking at the code for our Deck and Hand classes we can see explicit
calls to the Card
constructor __init__
invoked
by Card(cardnum)
and the __str__
method invoked via str(card)
. The
necessary Card class can be written as,
Notes:
- A
Card
object has a single attribute: its card number. - The
__str__
method calls on two otherCard
methods to get the string representations of the card's face value and suit:face_value
andsuit
. - The lists
FACE_VALUES
andSUITS
are class variables. All members of the class share access to them. Note that they are accessed by prefixing them with the class name, i.e. we useCard.SUITS
not justSUITS
.