python中 列表(List)转换为字符串(Str)的方法

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)
    result2 = str2.split()
    result3 = str3.split(', ')
    print(result1)
    print(result2)
    
    结果:
    ['a', 'b', 'c', 'd', 'e']
    ['a', 'b', 'c', 'd', 'e']
    ['a', 'b', 'c', 'd', 'e']

你可能感兴趣的:(python+request)