python中列表 元组 字符串如何互相转换
2013-09-09 11:41
573 查看
python中有三个内建函数:列表,元组和字符串,他们之间的互相转换使用三个函数,str(),tuple()和list(),具体示例如下所示:
>>> 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函数>>> "".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 中list(列表),tupe(元组),str(字符串),dict(字典)之间的相互转换
- python中列表元组字符串相互转换
- python 列表、字典、元组、字符串之间的转换