1、List列表转为Str字符串
List中存的是字符串的时候,一般是通过.join()函数去转换:
例 :
dataList = ['1', '2', '3', '4' ]
str1...= “ , ” + join(dataList )
print (dataList)
结果:
a b c d
2、Str转为List列表
主要就是通过str的split()函数,如果为空就用空格标识...:
例:
str1 = 'abcde'
str2 = 'a b c d e'
str3 = 'a, b, c, d, e'
result1 = list(str1)...split()
result3 = str3.split(', ')
print(result1)
print(result2)
结果:
['a', 'b'..., 'c', 'd', 'e']
['a', 'b', 'c', 'd', 'e']
['a', 'b', 'c', 'd', 'e']
发布者:全栈程序员栈长,转载请注明出处:https