Python中list、tuple、str和dict之间的相互转换
来源:互联网 发布:快递业务考试软件 编辑:程序博客网 时间:2024/05/19 18:46
1、字典(dict)
dict = {‘name’: ‘Zara’, ‘age’: 7, ‘class’: ‘First’}
1.1 字典——字符串
返回:
print type(str(dict)), str(dict)
- 1
- 1
1.2 字典——元组
返回:(‘age’, ‘name’, ‘class’)
print tuple(dict)
- 1
- 1
1.3 字典——元组
返回:(7, ‘Zara’, ‘First’)
print tuple(dict.values())
- 1
- 1
1.4 字典——列表
返回:[‘age’, ‘name’, ‘class’]
print list(dict)
- 1
- 1
1.5 字典——列表
print dict.values
2、元组
tup=(1, 2, 3, 4, 5)
2.1 元组——字符串
返回:(1, 2, 3, 4, 5)
print tup.__str__()
- 1
- 1
2.2 元组——列表
返回:[1, 2, 3, 4, 5]
print list(tup)
- 1
- 1
2.3 元组不可以转为字典
3、列表
nums=[1, 3, 5, 7, 8, 13, 20];
3.1 列表——字符串
返回:[1, 3, 5, 7, 8, 13, 20]
print str(nums)
- 1
- 1
3.2 列表——元组
返回:(1, 3, 5, 7, 8, 13, 20)
print tuple(nums)
- 1
- 1
3.3 列表不可以转为字典
4、字符串
4.1 字符串——元组
返回:(1, 2, 3)
print tuple(eval("(1,2,3)"))
- 1
- 1
4.2 字符串——列表
返回:[1, 2, 3]
print list(eval("(1,2,3)"))
- 1
- 1
4.3 字符串——字典
返回:
print type(eval("{'name':'ljq', 'age':24}"))
阅读全文
0 0
- Python中list、tuple、str和dict之间的相互转换
- Python中list、tuple、str和dict之间的相互转换
- Python中list、tuple、str和dict之间的相互转换
- python中list,tuple,str相互转换
- python3 list、tuple(元组)、str之间的相互转换
- Python list和tuple的相互转换
- Python中list,tuple,dict,set的区别和用法
- Python中list,tuple,dict,set的区别和用法
- Python中list,tuple,dict,set的区别和用法
- python 中list dict tuple的比较
- Python中list,tuple,dict的区别
- python下DataFrame, Series, ndarray, list, dict, tuple的相互转换
- Python List 、 tuple和dict
- python中str(字符串)、list(列表)、tuple(元组)、dict(字典)相互转化关系及字典键-值遍历
- python中 list和tuple 、dict和set区别
- Python基础数据结构(list, str, tuple, dict)
- python数据类型互换dict/list/tuple/str互换方法
- python基础31[list+tuple+set+dict+str+file的成员方法]
- 关于vmware开启虚拟机时出现internal error内部错误的解决方法记录
- Python学习----数字
- Oracle用户、表空间
- ubuntu 使用cron设置定时启动任务
- Python【map、reduce、filter】内置函数使用说明
- Python中list、tuple、str和dict之间的相互转换
- 632. Smallest Range
- Javascript函数表达式
- css属性
- 求大神指导
- kmp理解篇
- RecyclerView 的坑 1 Added View has RecyclerView as parent but view is not a real child. Unfiltered in
- shell命令之echo
- 将手机页面左右滚动固定