Python-将列表中的所有项合并为字符串

Python-将列表中的所有项合并为字符串,python,Python,有没有办法将列表中的所有项目合并为一个字符串 print(isbnl)# str(isbnl).strip('[]')) 您有两个选择: 如果列表中的项目已经是字符串: list_of_strings = ['abc', 'def', 'ghi'] # give a list of strings new_string = "".join(list_of_strings) # join them into a new string 如果列表中的项目不是全部字符串,则必须首先将它

有没有办法将列表中的所有项目合并为一个字符串

    print(isbnl)# str(isbnl).strip('[]'))
您有两个选择:

如果列表中的项目已经是字符串:

list_of_strings = ['abc', 'def', 'ghi'] # give a list of strings

new_string = "".join(list_of_strings)   # join them into a new string
如果列表中的项目不是全部字符串,则必须首先将它们转换为字符串:

list_of_nonstrings = [1.83, some_object, 4, 'abc'] # given a list of mixed types

# construct new list of strings for join function
list_of_strings = [str(thing) for thing in list_of_nonstrings]

new_string = "".join(list_0f_strings) # join into new string, just like before
现在您可以打印或操作
新字符串
,但您需要。

您的意思是
str.join()
?e、 加入(isbnl)?您忘了指定预期的输出。或者使用
print(*isbnl,sep=',')