python中数组,元组,字典和字符串之间的转换
2015-11-23 09:53
651 查看
python中数组,元组,字典和字符串之间的转换
>>> mytuple = (1,2,3) >>> print list(mytuple) # Tuple to list [1, 2, 3] >>> >>> mylist = [1,2,3] # List to tuple >>> print tuple(mylist) (1, 2, 3) >>> >>> mylist2 = [ ('blue',5), ('red',3), ('yellow',7) ] >>> print dict(mylist2) # List to dictionnary {'blue': 5, 'yellow': 7, 'red': 3} >>> >>> mystring = 'hello' >>> print list(mystring) # String to list ['h', 'e', 'l', 'l', 'o'] >>> >>> mylist3 = ['w','or','ld'] >>> print ''.join(mylist3) # List to string world >>>
相关文章推荐
- python批量打多渠道包
- Python 最佳实践
- python中使用多继承
- 利用Sublimetext3&virtualenv 打造一个Web&Python IDE
- python学习之路之案例1(修改haproxy的配置文件,并实现下线、上线的功能)
- ubuntu 14.04 打开Python2.7 IDLE
- python模块导入过程
- python中的map、filter、reduce函数
- python参数传递那些事
- python使用pickle序列化对象至文件
- python内置数据类型
- Python Env
- python之路第五篇之装饰器:(进阶篇)
- 学习Python (三)
- leetcode之Implement Trie (Prefix Tree)
- python 监控jvm脚本
- python-02:学习路线
- python-03:用最简单快速的方法入门
- Python模式匹配
- python线程池