我无法弄清楚为什么我得到这个:TypeError:'builtin_function_or_method'对象不可订阅

时间:2016-05-13 21:11:55

标签: python python-3.x typeerror

所以当我尝试使用我的代码时出现此错误。

File "/Users/max/Desktop/Code/Python/game.py", line 30, in <module>
        lineone.remove[0]       #or whatever number I use
    TypeError: 'builtin_function_or_method' object is not subscriptable

我的代码是

lineone = ['0', '0', '0', '0', '0', '0', '0']
linetwo = ['0', '0', '0', '0', '0']
linethree = ['0', '0', '0']
lineoneX = ['X', 'X', 'X', 'X', 'X', 'X', 'X']
linetwoX = ['X', 'X', 'X', 'X', 'X']
linethreeX = ['X', 'X', 'X']
notfirst = 0
player1 = input('''Enter player 1's name ''')
player2 = input('''Enter player 2's name ''')
print('The person who takes the last stone wins!')
print(lineone[0], lineone[1], lineone[2], lineone[3], lineone[4], lineone[5], lineone[6])
print(linetwo[0], linetwo[1], linetwo[2], linetwo[3], linetwo[4])
print(linethree[0], linethree[1], linethree[2])

while True:
    #WTD means -What to Delete
    WTD = input('Type the row number, then the amount of stones you want to take, in the format 1, 1. ')
          # Line One
    if WTD == '1, 1':
          lineone.remove[0]
    if WTD == '1, 2':
          lineone.remove[1]
    if WTD == '1, 3':
          lineone.remove[2]
    if WTD == '1, 4':
          lineone.remove[3]
    if WTD == '1, 5':
          lineone.remove[4]
    if WTD == '1, 6':
          lineone.remove[5]
    if WTD == '1, 7':
          lineone.remove[6]
          # Line Two
    if WTD == '2, 1':
          linetwo.remove[0]
    if WTD == '2, 2':
          linetwo.remove[1]
    if WTD == '2, 3':
          linetwo.remove[2]
    if WTD == '2, 4':
          linetwo.remove[3]
    if WTD == '2, 5':
          linetwo.remove[4]
          # Line Three
    if WTD == '3, 1':
          linetwo.remove[0]
    if WTD == '3, 2':
          linetwo.remove[1]
    if WTD == '2, 3':
          linetwo.remove[2]
    print(lineone)
    print(linetwo)
    print(linethree)

我看过很多其他地方,但我无法弄清楚为什么这不起作用。我正在使用方括号,我使用0而不是第一项的1。 所以请帮忙, 提前谢谢!

1 个答案:

答案 0 :(得分:2)

问题在于,您尝试使用删除之类的列表或词典,因为它是一个功能,这就是您获得TypeError: 'builtin_function_or_method' object is not subscriptable的原因。相反,如果您想删除第一个&#39; 0,请尝试lineone.remove('0')。元素,或用于例如lineone.pop(0)如果要删除第一个元素。查看docs了解详情。

相关问题