码迷,mamicode.com
首页 > 编程语言 > 详细

Python list 和 str 互转

时间:2017-10-04 20:47:54      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:命令   body   logs   post   之间   int   结果   join   字符串   

一、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]

Python list 和 str 互转

标签:命令   body   logs   post   之间   int   结果   join   字符串   

原文地址:http://www.cnblogs.com/anningwang/p/7627117.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!