Python怎么将列表转字符串

357次阅读
没有评论

Python怎么将列表转字符串

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 ""
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:Python基础教程2022-12-07发表,共计661字。
新手QQ群:570568346,欢迎进群讨论 Python51学习