我查看了所有錯誤以找到解決方案,但找不到工作解決方案!錯誤:列表索引超出範圍Python
我得到列表索引超出範圍錯誤。
「手」和「甲板」都列在這裏。
def draw(self,amount):
for x in range(amount):
print len(self.deck)
if len(self.deck) == 0:
self.shuffle
else:
pass
self.hand.append(self.deck[0])
self.deck.remove(self.deck[0])
據我所知,它是給錯誤,因爲錯誤通過時,甲板只是[]。爲什麼會發生這種情況,我該如何解決?
這是因爲它們中的一個(或它們兩個)列表是空的(或者在您執行'self.deck.remove(self.deck [0])'時變爲空)。我們可以看到這些列表嗎? –
可能提供完整的代碼。 – nehemiah
需要更多關於手和甲板的信息。 –