【发布时间】:2020-03-26 18:29:50
【问题描述】:
我在self.deck 列表中附加了所有可能的卡片,但是当我尝试使用字符串表示方法打印出列表时,它给了我<__main__.Deck object at 0x00238148> 我不知道为什么!我的代码在下面,如果有人可以查看它并告诉我如何在Deck 类中获取所有card,我将不胜感激?
suits = ('Hearts', 'Diamonds', 'Spades', 'Clubs')
ranks = ('Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Jack', 'Queen', 'King', 'Ace')
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.deck = []
for suit in suits:
for rank in ranks:
self.deck.append(Card(suit, rank))
def __str__(self):
for card in self.deck:
return card
deck = Deck()
print(deck)
【问题讨论】:
标签: python-3.x loops oop blackjack