网络编程
位置:首页>> 网络编程>> Python编程>> Python实现按逗号分隔列表的方法

Python实现按逗号分隔列表的方法

作者:JD_peterLi  发布时间:2023-06-08 08:32:16 

标签: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)

来源:https://blog.csdn.net/I_peter/article/details/79020205

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com