This question already has answers here:
Concatenate item in list to strings
(6个答案)
12个月前关闭。
我正在使用一个python程序,其中我必须连接列表中的字符以使像['h''e''l''l''o']这样的字符串成为问候。我正在使用
我的代码是:
输出:
(6个答案)
12个月前关闭。
我正在使用一个python程序,其中我必须连接列表中的字符以使像['h''e''l''l''o']这样的字符串成为问候。我正在使用
for
循环执行此操作。我正在寻找一种可以完成这项工作的内置方法。我搜索了,但是没有找到任何方法。我的代码是:
list=['h','e','l','l','o']
s=""
for i in list:
s+=i
print(s)
最佳答案
尝试join()
方法:
s = "".join(list)
输出:
s = 'hello'