简体   繁体   English

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

[英]Python3 - TypeError: list indices must be integers or slices, not str - List

I've just recently started exploring Python and can't seem to figure out a way to code this. 我最近才刚刚开始探索Python,但似乎找不到一种编码方法。 I'm guessing the fix is fairly simple. 我猜想修复很简单。 Can someone help me? 有人能帮我吗?

temp = 0
for i in list[::-1]:
    temp = temp + 1.11
    list[i].append("{0:.2f}".format(temp))

You already have the list item as i and you can just append to it. 您已经有了列表项,就像i ,您可以追加它。 list[i] is indexing the list with the list item (which I think is another list) and not index. list[i]用列表项(我认为是另一个列表)对列表建立索引,而不是索引。

So instead of 所以代替

list[i].append("{0:.2f}".format(temp))

you should do 你应该做

i.append("{0:.2f}".format(temp))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python3:TypeError:列表索引必须是整数或切片,而不是str - Python3: TypeError: list indices must be integers or slices, not str Python3切片,TypeError:列表索引必须是整数或切片,而不是列表 - Python3 Slicing, TypeError: list indices must be integers or slices, not list “TypeError:list indices必须是整数或切片,而不是str” - “TypeError: list indices must be integers or slices, not str” TypeError:列表索引必须是整数或切片,而不是 str - TypeError: List indices must be integers or slices and not str 类型错误:列表索引必须是整数或切片,而不是 str - TypeError: list indices must be integers or slices, not str “TypeError:列表索引必须是整数或切片,而不是 str” - "TypeError: list indices must be integers or slices, not str" TypeError:列表索引必须是整数或切片而不是 str - TypeError: list indices must be integers or slices not str 类型错误:列表索引必须是整数或切片,而不是 str - TypeError: list indices must be integers or slices, not str 使用 Python TypeError 解析 JSON:列表索引必须是整数或切片,而不是 str - Parsing JSON with Python TypeError: list indices must be integers or slices, not str Python JSON TypeError 列表索引必须是整数或切片,而不是 str - Python JSON TypeError list indices must be integers or slices, not str
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM