python中字符串和列表的相互转换
2014-09-06 20:22
330 查看
python中经常会遇到字符串和列表的相互转换的问题,解决方法如下:
1.字符串转换为列表:
直接调用list()
str1 = "hello"
list1 = list(str1)2.列表转换为字符串:
这个时候不能直接调用str(),否则它会将列表当作整体变为字符串。
应该采用下面的方法:
list2 = ['a','b','c','d']
str2 = ''.join(list2)
join()是字符串的内置方法。
1.字符串转换为列表:
直接调用list()
str1 = "hello"
list1 = list(str1)2.列表转换为字符串:
这个时候不能直接调用str(),否则它会将列表当作整体变为字符串。
应该采用下面的方法:
list2 = ['a','b','c','d']
str2 = ''.join(list2)
join()是字符串的内置方法。
相关文章推荐
- python列表,元组,字典和字符串之间的相互转换
- python 字符串,列表,元组,字典相互转换
- python基础学习——列表(list), 元祖(tuple), 字典(dict), 字符串(string), 集合(set) 介绍及相互转换
- python 中list(列表),tupe(元组),str(字符串),dict(字典)之间的相互转换
- python 字符串,列表,元组,字典相互转换
- python字符串列表字典相互转换
- python字符串与列表的相互转换
- python中列表,元组,字典,字符串相互转换
- python基础数据结构——列表(list), 元祖(tuple), 字典(dict), 字符串(string), 集合(set) 介绍及相互转换
- python字符串、列表、字典相互转换
- 收集: python中列表,元组,字符串 相互转换, IO 数据处理,行数据切割
- python中列表元组字符串相互转换
- python列表 字符串 转换
- [python] 字符串与列表、字典的转换
- python中列表,元组,字符串 互相转换
- python 列表转换成字符串
- python 字符串,元组, 列表,字典之间的转换
- python 列表 字符串 转换
- python实现字符串和日期相互转换的方法
- python中列表,元组,字符串如何互相转换