极客小将

您现在的位置是:首页 » python编程资讯

资讯内容

Python怎么将列表转字符串

极客小将2020-12-26-
简介Python怎么将列表转字符串例子:将列表 temp_list=['h','e','l','l','o']转换成字符串'hello',代码如下:temp_list = [&#

svz少儿编程网-Scratch_Python_教程_免费儿童编程学习平台

python怎么将列表转字符串svz少儿编程网-Scratch_Python_教程_免费儿童编程学习平台

例子:svz少儿编程网-Scratch_Python_教程_免费儿童编程学习平台

将列表 temp_list = ['h', 'e', 'l', 'l', 'o'] 转换成字符串'hello',代码如下:svz少儿编程网-Scratch_Python_教程_免费儿童编程学习平台

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

推荐学习《python教程》。svz少儿编程网-Scratch_Python_教程_免费儿童编程学习平台

字符串对象的方法join其描述如下:svz少儿编程网-Scratch_Python_教程_免费儿童编程学习平台

大概意思是:s.join(iterable)是将括号内的迭代对象(如列表)使用s字符串作为链接将迭代对象中的元素拼接成一个字符串,返回该字符串。svz少儿编程网-Scratch_Python_教程_免费儿童编程学习平台

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 ""

网友点评

共有5条评论来说两句吧...

在线客服