[英]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.