【发布时间】:2015-06-16 11:21:36
【问题描述】:
假设我有一个字符串列表,我想将这些字符串组合成一个由下划线分隔的字符串。我知道我可以使用循环来做到这一点,但是 python 在没有循环的情况下做了很多事情。 python中有什么东西已经有这个功能了吗?例如我有:
string_list = ['Hello', 'there', 'how', 'are', 'you?']
我想制作一个像这样的字符串:
'Hello_there_how_are_you?'
我尝试过的:
mystr = ''
mystr.join(string_list+'_')
但这给出了一个“TypeError: can only concatenate list (not "str") to list”。我知道这很简单,但不是很明显。
【问题讨论】:
标签: python string python-2.7