python中列表,元组,字符串如何互相转换
2015-02-23 09:35
609 查看
python中有三个内建函数:列表,元组和字符串,他们之间的互相转换使用三个函数,str(),tuple()和list(),具体示例如下所示:
列表和元组转换为字符串则必须依靠join函数
>>> 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 字符串,元组, 列表,字典之间的转换