列表中的python项添加到字符串

pha*_*s15 1 python

我试图将列表中的项连接到字符串上.

list = ['a', 'b', 'c', 'd']
string = ''
for i in list:
    string.join(str(i))
Run Code Online (Sandbox Code Playgroud)

Dan*_*den 6

你不需要循环:

items = ['a', 'b', 'c', 'd']
result = "".join(items)
Run Code Online (Sandbox Code Playgroud)

请注意,使用list变量名称是个坏主意,因为这会阻止您使用list内置类型.


Sve*_*ach 6

这是你想要的?

>>> my_list = ['a', 'b', 'c', 'd']
>>> "".join(my_list)
'abcd'
Run Code Online (Sandbox Code Playgroud)

您不应该将其list用作变量名,因为这会影响内置类list.