时间:2021-07-21 08:21:13 | 栏目:Python代码 | 点击:次
方法一:
def commaSpiltList(self, listData): listData = list(listData) strs = str(listData[0]) for letter in range(1, len(listData) - 1): strs = strs + ',' + str(listData[letter]) strs += ',' + str(listData[len(listData) - 1]) print(strs)
方法二:
#!/usr/bin/python # -*- coding: UTF-8 -*- L = [1,2,3,4,5] s1 = ','.join(str(n) for n in L) print s1
注意:字符串中替换字符的方法
s1 = ','.join(str(n) for n in listData)