您现在的位置是:课程教程文章

Python怎么将列表转字符串

2023-12-18 19:18课程教程文章 人已围观

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 ""
课程教程:Python怎么将列表转字符串

上一篇:Python有表格显示界面吗

下一篇:没有了

站点信息

  • 文章统计篇文章