python中 列表(List)转换为字符串(Str)的方法 |
您所在的位置:网站首页 › python将list转换为str › python中 列表(List)转换为字符串(Str)的方法 |
1、List列表转为Str字符串 List中存的是字符串的时候,一般是通过.join()函数去转换: 例 : dataList = ['1', '2', '3', '4' ] str1 = “ , ” + join(dataList ) print (dataList) 结果: a b c d2、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'] |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |