python-3.x - 'builtin_function_or_method' object is not subscriptable error' 是什么意思?

标签 python-3.x

关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

6年前关闭。




Improve this question




所以我正在尝试编写一个好的 war 游戏,当我尝试将一个对象(一张卡片)从一个列表(手)移动到另一个列表时出现错误。还有其他一些关于此的帖子,但我无法拼凑出该怎么做......
这是代码:

import random
cardvalues = {"ace" : 13 , "2" : 2 , "3" : 3 , "4" : 4 , "5" : 5 , "6" : 6, "7" : 7 , "8" : 8 , "9" : 9, "10" : 10 , "jack" : 11 , "queen" : 12 , "king" : 13}
suits = {"clubs" : 1, "diamonds" : 2 , "spades" : 3 , "hearts" : 4}
deck = []
currentDeck = []

class card:
    def __init__ (self, value, suit):
        if value not in cardvalues:
            raise RuntimeError("must input valid card value")...

### [此处的代码已被删除,因为它没有引起问题]
def battle():            
    if hand1[0] >= hand2[0]:
        hand1.append[hand2.pop(0)] #The error happens in this function in the .append
        print("player 1 won the battle")
    elif hand1[0] < hand2[0]:
        hand2.append[hand1.pop(0)]
        print("player 2 won the battle")
    else:
        raise RuntimeError("something wrong")


while len(hand1) > 0:
    while len(hand2) > 0:
        battle()
if len(hand1) == 0:
    print("PLAYER 2 WON THE WAR")
elif len(hand2) == 0:
    print("PLAYER 1 WON THE WAR")
else:
    print("no one won?")

谢谢!

我不仅需要帮助找出我的错误,而且它意味着什么?

最佳答案

你用过[]而不是 ()尝试调用 append 时.

关于python-3.x - 'builtin_function_or_method' object is not subscriptable error' 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33656966/

相关文章:

python - 使用 python : can't get a column 从维基百科中抓取表格

python-3.x - 我正在尝试在 windows10 上使用 pip 安装 fbprophet 并显示以下错误

python - 如何检查用户输入的字符列表中是否有相同的字符?

python - python-3中的 '%% time'是什么意思?

Python requests lib 花费的时间比执行 get 请求的时间要长

python - 如何更改此代码以使用上下文管理器?

python - 如何在独立的环境中嵌入 Bokeh 服务器

unicode - write()-在Python 3.x中编码字符串

python - Tensorflow 无法识别 cudart64_101.dll

Python 3 读取行内缺少对象的 json 文件