I am designing a deck class that has init() method with initially has an empty list. Then I append my cards to the list. I am trying to create an x instance and access the shuffled version of the deck of cards. I know there are many solutions posted already. I just want to understand with my logic I am able to print the address of the card elements and not the deck itself. While trying to debug ,I am not understanding whether print(x.cards_in_deck) is printing the location or the x.shuffle... .Any good reference for Pycharm debugging will also be highly appreciated.
suits = ('Hearts', 'Diamonds', 'Spades', 'Clubs')
ranks = ('Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Jack', 'Queen', 'King', 'Ace')
values = {'Two':2, 'Three':3, 'Four':4, 'Five':5, 'Six':6, 'Seven':7, 'Eight':8, 'Nine':9, 'Ten':10, 'Jack':10,
'Queen':10, 'King':10, 'Ace':11}
class Card:
def __init__(self,suit,rank):
self.suit = suit
self.rank = rank
def __str__(self):
return self.rank +' of '+self.suit
class Deck:
def __init__(self):
self.cards_in_deck = []
for suit in suits:
for rank in ranks:
self.cards_in_deck.append(Card(suit, rank))
#return self.cards_in_deck
def __str__(self):
# for card in Deck.cards_in_deck:
# return(card)
return self.cards_in_deck
def shuffle_cards(self):
return random.shuffle(self.cards_in_deck)
x = Deck()
print(x.cards_in_deck,sep ='\n')
print(x.shuffle_cards(),sep = '\n')