首页 > 编程语言 > 详细

python怎么将列表转换成字符串

时间:2019-05-26 21:09:53      阅读:483      评论:0      收藏:0      [点我收藏+]

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

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

解决方法是使用字符串对象的方法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怎么将列表转换成字符串

原文:https://www.cnblogs.com/hwnzy/p/10927484.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!