我正在使用 Python 并希望能够创建一个数组,然后将值与特定格式的字符串连接起来。我希望下面能解释我的意思。
name_strings = ['Team 1', 'Team 2']
print "% posted a challenge to %s", %(name_strings)
name_strings
中的每个值都将放置在 %s
位置。非常感谢任何帮助。
最佳答案
一种方法可能是将数组扩展到 str format函数...
array_of_strings = ['Team1', 'Team2']
message = '{0} posted a challenge to {1}'
print(message.format(*array_of_strings))
#> Team1 posted a challenge to Team2
关于python - 将字符串与数组值连接起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20778304/