Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python列表中添加/更新值_Python_List_Coordinates - Fatal编程技术网

在python列表中添加/更新值

在python列表中添加/更新值,python,list,coordinates,Python,List,Coordinates,假设我有一个坐标为的列表,我想将我的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新手,需要一些帮助!谢谢大家! 要在coords[2]中添加10,您只需编写: coords[2] +

假设我有一个坐标为的列表,我想将我的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新手,需要一些帮助!谢谢大家!

要在
coords[2]
中添加10,您只需编写:

coords[2] += 10

您不需要更新整个数组/列表,只需访问需要更新的索引即可

 coords[2] = coords[2] + 10

coords now=
[0,1.2,10]

这将是
coords[2]+=10
。在值中添加10,从列表开始的两个位置
coords
删除
coords
[coords[0],…]
coords=[coords[0],0,coords[2]+10]
@codegoblin1996答案解决了你的问题吗?如果是,考虑关闭它。