Python 我能';我不明白为什么会这样:TypeError:';内置函数或方法';对象不可下标
所以当我尝试使用我的代码时,我得到了这个错误Python 我能';我不明白为什么会这样:TypeError:';内置函数或方法';对象不可下标,python,python-3.x,typeerror,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 我已经在很多其他地方看过了,但我不明白为什么
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
我已经在很多其他地方看过了,但我不明白为什么这不起作用。我使用方括号,第一项使用0而不是1。
所以请帮忙,
提前谢谢 问题是,当它是一个函数时,您试图像使用列表或字典一样使用remove,这就是为什么会出现
TypeError:“builtin\u function\u或\u method”对象不可下标的原因。相反,如果要删除第一个“0”元素,则应尝试lineone.remove('0')
,如果要删除第一个元素,则应尝试lineone.pop(0)
。查看详细信息。删除
是一种方法;你用括号而不是括号来称呼它。它也不做你想做的事情,所以在你改变括号后你仍然会有问题。你的意思是:它也不做你想做的事情你试图从列表中删除指定数量的项目<代码>删除
不会这样做。
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)