list与str互转

import string
str = 'abcde'
list = list(str)
list
['a', 'b', 'c', 'd', 'e']
str
'abcde'
str_convert = ''.join(list)
str_convert
'abcde'

 

一、list转字符串

命令:''.join(list)
其中,引号中是字符之间的分割符,如“,”,“;”,“\t”等等
如:
list = [1, 2, 3, 4, 5]
''.join(list) 结果即为:12345
','.join(list) 结果即为:1,2,3,4,5

二、字符串转list

print list('12345')
输出: ['1', '2', '3', '4', '5']
print list(map(int, '12345'))
输出: [1, 2, 3, 4, 5]

str2 = "123 sjhid dhi" 
list2 = str2.split() #or list2 = str2.split(" ") 
print list2 
['123', 'sjhid', 'dhi']

str3 = "www.google.com" 
list3 = str3.split(".") 
print list3 
['www', 'google', 'com']

 

python list 转换为str

xiaoquInfo  = ['暂无参考均价', '中仪花园海伦堡', '113.403781', '22.540973', '2008年建成', '塔楼', '2元/平米/月', '海伦堡物业', '中山市中仪花园房地产开发有限公司', '19栋', '754户', '暂无门店信息']
#转换成为字符串并且以|||进行分割
Details = ('|||').join(xiaoquInfo)

 

posted @ 2018-02-21 15:14  Gaoyongxian666  阅读(431)  评论(0编辑  收藏  举报