Python怎么将列表转字符串

图片[1]-Python怎么将列表转字符串-uusu优素-乐高,模型,3d打印,编程

Python怎么将列表转字符串

例子:

将列表temp_list = ['h', 'e', 'l', 'l', 'o'] 转换成字符串'hello',代码如下:

temp_list=['h','e','l','l','o']
result=''.join(temp_list)
print(result)
hello

推荐学习《Python教程》。

字符串对象的方法join其描述如下:

defjoin(self,iterable):#realsignatureunknown;restoredfrom__doc__
"""
S.join(iterable)->str

Returnastringwhichistheconcatenationofthestringsinthe
iterable.TheseparatorbetweenelementsisS.
"""
return""
原文来自:https://www.py.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享