当前位置:网站首页>eval函数,全局、本地变量
eval函数,全局、本地变量
2022-06-27 18:27:00 【LRJ-jonas】
eval()函数:
a=10; print(eval("a+1"))eval函数将“字符串文本”变为代码变量
在Python中evel()函数的语法格式为eval(expression, globals=None, locals=None)
global:g local:t
a=10
b=20
c=30
g={'a':6,'b':8}
t={'b':100,'c':10}
print(eval('a+b+c',g,t))
a和c的值分别去字典g和字典t中的值,当globals和locals中都有参数b时取locals中的值。所以a=6,b=100,c=10。运行结果为116
应用:可以使用一行代码就实现计算器的功能print(eval(input('请输入')))。
缺点:但是因为它具有可以将字符串转成表达式执行的特性,所以它也就可以去执行系统命令。这样很容易被别有用心的人用来执行系统命令,删除关键系统文件。
边栏推荐
- Graylog 新一代日志收集预警系统安装配置
- Question brushing record: easy array (continuously updated)
- [bug] Lenovo Xiaoxin has a problem. Your pin is unavailable.
- SQL报了一个不常见的错误,让新来的实习生懵了
- Data intelligence enters the "deep water area", and data governance is the key
- Longitude and latitude analysis
- Database transactions
- 散列表(Hash)-复习
- Redis 大 key 问题处理总结
- 【help】JVM的CPU资源占用过高问题的排查
猜你喜欢
随机推荐
数据库事务
Batch insert data using MySQL bulkloader
Redis 大 key 问题处理总结
SQL reported an unusual error, which confused the new interns
云原生安全指南: 从零开始学 Kubernetes 攻防
数据仓库体系之贴源层、历史层
通过 Cargo 管理 Rust 项目
优维HyperInsight:掘金164.94亿美元可观测市场的“金锄头”?
【debug】平台工程接口调试
【精品必读】Linux系统Oracle数据库趣解子查询
Common shell script commands (III)
Linux系统ORACLE 19C OEM监控管理
Database index
1028 List Sorting
Mobile low code development theme month | visual development one click generation of professional source code
Summary of redis big key problem handling
429- binary tree (108. convert the ordered array into a binary search tree, 538. convert the binary search tree into an accumulation tree, 106. construct a binary tree from the middle order and post o
连接集成开发专题月 | 企业主数据治理的驱动因素
海量数据出席兰州openGauss Meetup(生态全国行)活动,以企业级数据库赋能用户应用升级
Type the URL to the web page display. What happened during this period?


![[debug] platform engineering interface debugging](/img/bc/ec630358b039c2a9551b7ae99d7fb3.png)





