python列表转换为字符串

前端之家收集整理的这篇文章主要介绍了python列表转换为字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

对于非纯字符串组成的列表,需要使用map(str,列表)转换,纯字符串组成的列表则不需要转换

list1 = [1,2,3,4,5]
c = ','.join(map(str,list1))
print(c)
print(type(c))


list2 = ['1','2','3','4','5']
d = ','.join(list2)
print(d)
print(type(d))


 

猜你在找的Python相关文章