Build a Deck of Cards with OO Python
We will build a deck of cards with Object-Orientated Programming.
Step 1: Prepare our classes:
We will have three classes. A class Card, class Deck and class Player . Each of these will inherit from the object. We create an init method for each class.
Step 2: Create our class Card:
The Card is going to take a suit and value self. We’re going to create the attributes suit, value and set them equal to whatever we pass in when we create a card.
We create another method to show the card. Everything takes self so we have access it’ s attribute self. In the show method we want to print out the card, so we make a string that will print out the value and the suit.
We are now done with the Card class! Lets test this by creating an instance of the card:
Step 3: Create our class Deck:
When we create a deck what do we want to do? Well we might first want to build our deck with 52…