我有一个名单,我希望把它的元素里面一个for循环的字符串是这样的:如何使用列表的索引做串插在一个for循环在python
my_list = ["Germany", "England", "Spain", "France"]
for this in that:
do stuff
print(my_list[0]+ some other stuff)
输出应该是像:
Germany + some other stuff
England + some other stuff
Spain + some other stuff
France + some other stuff
我怎么能回路串插指数呢?
谢谢!
编辑:循环有点不同。它更像这样:
for foo in bar:
another_bar = []
for x, y in foo:
do stuff
a = object.method()
another_bar.append(my_list[0]+a)
我需要将列表的字符串放入第二层嵌套循环。这里不能使用zip。
据我所知这是你想要的东西:my_list = [“德国”,“英格兰”,“西班牙”,“法国”] 为国家my_list: 打印(国+“的一些其他的东西” ) –
@ 0x1我编辑了您的修改以修复缩进。请确保它符合您的意图。另外,你的代码需要更多的结构。例如,'index'没有被定义。请参阅[MCVE]。 – Alexander