【发布时间】:2023-01-09 18:34:27
【问题描述】:
我正在尝试添加不同的词列表按顺序行。但是,我坚持下去。你能告诉我如何进行吗?我收到类型错误,无法获得输出。
我试图获得的输出:
it starts with: one or more.
it starts with: two or more.
it starts with: three or more.
我试过的代码:
a=["one","two","three"]
for i in a:
print("it starts with: " + a[i] + "or more")
我得到的结果:
TypeError: list indices must be integers or slices, not str
【问题讨论】:
-
i已经是值了。for i in a: print("it starts with: " + i + " or more")
标签: python string list loops printing