python - 在 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 新手,可以使用一些帮助!谢谢!
解决方案
为了给你加 10,coords[2]
你可以写:
coords[2] += 10
推荐阅读
- python - 如何修复“没有名为'easysnmp'的模块”
- google-apps-script - 使用 Google Script 抓取网页,异步网站?
- ruby-on-rails - 查询包含所有项目的关联
- html - 为什么位置固定的标签在不同的html页面上的位置略有不同?
- javascript - 有什么办法可以强制浏览器不提示记住密码框吗?
- kubernetes - Cert-manager 在带有 webhook 的 kubernetes 上失败
- oop - Perl 6 多方法从不匹配预期的签名
- sql - 获取更改状态的记录数
- delphi - 是否有允许超链接的多行文本对象?
- android - 使用 PendingIntent 时重复数据