Python eval函数原理及用法解析
作者:迎风而来 时间:2021-04-29 05:17:18
eval函数就是实现list、dict、tuple与str之间的转化
str函数把list,dict,tuple转为为字符串
一、字符串转换成列表
a = "[[1,2], [3,4], [5,6], [7,8], [9,0]]"
print(type(a))
b = eval(a)print(type(b))
print(b)
二、字符串转换成字典
a = "{1: 'a', 2: 'b'}"
print(type(a))
b = eval(a)
print(type(b))
print(b)
三、字符串转换成元组
a = "([1,2], [3,4], [5,6], [7,8], (9,0))"
print(type(a))
b=eval(a)
print(type(b))
print(b)
来源:https://www.cnblogs.com/sui776265233/p/9900709.html
标签:Python,eval,函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
教你两步解决conda安装pytorch时下载速度慢or超时的问题
2022-04-12 17:19:59
![](https://img.aspxhome.com/file/2023/5/110435_0s.png)
Python实现五子棋人机对战 和人人对战
2023-01-14 07:59:52
oracle命令行删除与创建用户
2008-01-02 17:01:00
在 Python 应用中使用 MongoDB的方法
2023-09-13 21:53:11
详解python中的线程与线程池
2022-02-02 18:27:19
Python自动化实战之接口请求的实现
2021-01-15 15:44:58
![](https://img.aspxhome.com/file/2023/6/115056_0s.jpg)
深入学习Python中的上下文管理器与else块
2023-05-11 08:57:53
python中的错误如何查看
2021-05-03 08:31:22
javascript同步服务器时间和同步倒计时小技巧
2023-08-27 22:10:58
![](https://img.aspxhome.com/file/2023/6/56116_0s.jpg)
css学习笔记: 重置默认样式 css reset
2009-07-19 14:30:00
![](https://img.aspxhome.com/file/UploadPic/20097/19/11e426f4e93g214-59s.jpg)
Python 爬虫学习笔记之单线程爬虫
2021-09-23 10:47:27
![](https://img.aspxhome.com/file/2023/1/110231_0s.png)
Python竟然能剪辑视频
2021-09-03 08:12:54
![](https://img.aspxhome.com/file/2023/7/83827_0s.gif)
分享Python 中的 7 种交叉验证方法
2023-09-18 19:10:33
![](https://img.aspxhome.com/file/2023/1/81481_0s.png)
python函数的重新定义及练习
2023-10-12 22:47:55
![](https://img.aspxhome.com/file/2023/8/63528_0s.png)
SQL查询效率:100w数据查询只需要1秒钟
2008-12-09 14:36:00
python制作填词游戏步骤详解
2023-03-09 19:46:47
![](https://img.aspxhome.com/file/2023/5/89365_0s.png)
Windows下安装Django框架的方法简明教程
2021-06-26 20:26:13
![](https://img.aspxhome.com/file/2023/3/100943_0s.png)
Python中if __name__==‘__main__‘用法详情
2021-07-18 02:38:20
![](https://img.aspxhome.com/file/2023/1/67341_0s.jpg)
python 对txt中每行内容进行批量替换的方法
2022-12-29 21:37:45
![](https://img.aspxhome.com/file/2023/1/67841_0s.jpg)
django之常用命令详解
2023-02-04 07:25:19