2016-05-13 53 views
1

所以我尝试使用我的代码时出现此错误。我不明白为什么我会得到这个:TypeError:'builtin_function_or_method'对象不是可订阅的

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。 所以请帮助, 在此先感谢!

+0

'remove'是一种方法;你用括号括起来而不是括号。它也没有做你想做的事情,所以你在改变方括号后仍然会遇到问题。 – user2357112

+0

你是什么意思:它也没有做你想做的事 – Maximus

+0

你试图从列表中删除指定数量的项目。 '删除'不这样做。 – user2357112

回答

2

问题是,你正在尝试使用删除像一个列表或字典,而它是一个函数,这就是为什么你得到TypeError: 'builtin_function_or_method' object is not subscriptable。如果你想删除第一个'0'元素,或者例如,你应该尝试lineone.remove('0')lineone.pop(0)如果你想删除第一个元素。详情请查阅docs

相关问题