TypeError:列表索引必须是整数或切片,而不是 str

过去两天我一直在尝试解决此错误,但我无法解决。


我必须将值(这是一个列表)传递给函数,但它说:


Typerror :list indices must be integers or slices and not str.

这是我的代码:


def input_execute(board, position, mark):

    board[position] = mark


position = input('enter the position')

input_execute(board_items, position, 'x')

输出:


enter the position:5

如果我输入它显示的位置:


Typerror :list indices must be integers or slices and not str.


慕侠2389804
浏览 58回答 1
1回答

慕盖茨4494581

下面的行返回字符串position=input('enter the position')现在将此行更改为position=int(input('enter the position : '))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python