首页 > 解决方案 > 在 python 列表中添加/更新一个值

问题描述

假设我有一个包含坐标的列表,我想将我的 z 坐标操作 10:

coords = [0, 1.2, 0] # x y z

我一直在做以下事情:

coords = coords[coords[0], 0, coords[2] + 10]

但我收到以下错误:

TypeError: list indices must be integers, not tuple

有谁知道我哪里出错了?我是 python 新手,可以使用一些帮助!谢谢!

标签: pythonlistcoordinates

解决方案


为了给你加 10,coords[2]你可以写:

coords[2] += 10

推荐阅读