【发布时间】:2022-12-03 03:09:09
【问题描述】:
我有一个简单的字符串和一个列表:
string = "the secret key is A"
list = ["123","234","345"]
我需要替换一个项目(“A”),将该项目与列表中的另一个项目(“A123”)组合起来,次数与列表中的项目数一样多。基本上我想达到的结果是:
"the secret key is A123"
"the secret key is A234"
"the secret key is A345"
我知道我需要使用 for 循环,但我无法将这些项目连接在一起。
【问题讨论】:
-
如果键在字符串的其他地方,输出会是什么?例如:
"And the secret key is A"?