品易云推流 关闭
文章详情页
文章 > Python常见问题 > Python怎么将列表转字符串

Python怎么将列表转字符串

头像

月亮邮递员

2020-04-03 17:38:1516596浏览 · 0收藏 · 0评论

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其描述如下:

大概意思是:s.join(iterable)是将括号内的迭代对象(如列表)使用s字符串作为链接将迭代对象中的元素拼接成一个字符串,返回该字符串。

def join(self, iterable): # real signature unknown; restored from __doc__
        """
        S.join(iterable) -> str
        
        Return a string which is the concatenation of the strings in the
        iterable.  The separator between elements is S.
        """
        return ""
关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图