python中列表,元组,字符串如何互相转换
2013-08-12 20:08
519 查看
python中有三个内建函数:列表,元组和字符串,他们之间的互相转换使用三个函数,str(),tuple()和list(),具体示例如下所示:
列表和元组转换为字符串则必须依靠join函数
转自:http://blog.csdn.net/sruru/article/details/7803208
>>> s = "xxxxx" >>> list(s) ['x', 'x', 'x', 'x', 'x'] >>> tuple(s) ('x', 'x', 'x', 'x', 'x') >>> tuple(list(s)) ('x', 'x', 'x', 'x', 'x') >>> list(tuple(s)) ['x', 'x', 'x', 'x', 'x'] |
>>> "".join(tuple(s)) 'xxxxx' >>> "".join(list(s)) 'xxxxx' >>> str(tuple(s)) "('x', 'x', 'x', 'x', 'x')" >>> |
相关文章推荐
- python中列表,元组,字符串如何互相转换
- python中列表,元组,字符串如何互相转换
- Python学习:列表,元组,字符串如何互相转换
- python中列表,元组,字符串如何互相转换
- python中列表,元组,字符串如何互相转换
- python中列表,元组,字符串如何互相转换
- python中列表 元组 字符串如何互相转换
- python中列表,元组,字符串如何互相转换
- python中列表,元组,字符串如何互相转换
- python中列表,元组,字符串 互相转换
- Python字符串、元组、列表、字典互相转换的方法
- Python字符串、元组、列表、字典互相转换的方法
- Python字符串、元组、列表、字典互相转换的方法
- 【知识】Python中字符串、元组、列表、字典的互相转换
- Python字符串、元组、列表、字典互相转换的方法
- python中列表,元组,字符串互相转换
- Python中列表、元组、字符串的互相转换
- python 字符串,元组,列表,词典转换
- python 字符串,列表,元组,字典相互转换
- python基础-列表、元组、range、列表字符串转换