为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕侠2389804 2022-11-01 14:45:03
过去两天我一直在尝试解决此错误,但我无法解决。我必须将值(这是一个列表)传递给函数,但它说:Typerror :list indices must be integers or slices and not str.这是我的代码:def input_execute(board, position, mark):    board[position] = markposition = 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.
查看完整描述

1 回答

?
慕盖茨4494581

TA贡献1850条经验 获得超11个赞

下面的行返回字符串

position=input('enter the position')

现在将此行更改为

position=int(input('enter the position : '))


查看完整回答
反对 回复 2022-11-01
  • 1 回答
  • 0 关注
  • 55 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信