当前位置:网站首页>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('请输入')))。
缺点:但是因为它具有可以将字符串转成表达式执行的特性,所以它也就可以去执行系统命令。这样很容易被别有用心的人用来执行系统命令,删除关键系统文件。
边栏推荐
- 本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
- 从指令交读掌握函数调用堆栈详细过程
- 智联招聘的基于 Nebula Graph 的推荐实践分享
- Pyhton crawls Baidu library text and writes it into word document
- Redis cluster Series II
- 1028 List Sorting
- 云原生存储解决方案Rook-Ceph与Rainbond结合的实践
- [bug] Lenovo Xiaoxin has a problem. Your pin is unavailable.
- 在开发数字藏品时,文博机构该如何把握公益和商业的尺度?如何确保文物数据的安全?
- 难怪大家丢掉了postman而选择 Apifox
猜你喜欢

主键选择选择自增还是序列?

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

Univision hyperinsight: Nuggets' $16.494 billion "gold hoe" in the observable market?

数智化进入“深水区”,数据治理是关键

Type the URL to the web page display. What happened during this period?

At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions

Accumulating power in the middle stage, UFIDA IUAP builds a new base for digital intelligence of social enterprises

数据库引擎

Redis data structure

SQL审核平台权限模块介绍和账号创建教程
随机推荐
【STL编程】【竞赛常用】【part 2】
难怪大家丢掉了postman而选择 Apifox
Mobile low code development theme month | visual development one click generation of professional source code
muduo
DBeaver恢复和备份数据库的方式
花了6个月时间完成本科优秀毕业设计,我做了什么?
[login interface]
Postman Chinese tutorial (postman Chinese version)
Database index
[bug] there is an error uploading the picture (413 request entity too large)
1023 Have Fun with Numbers
redis数据结构
什么是堆栈?
云原生安全指南: 从零开始学 Kubernetes 攻防
Logcli Loki command line tool
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
最佳实践:优化Postgres查询性能(下)
【help】JVM的CPU资源占用过高问题的排查
从指令交读掌握函数调用堆栈详细过程
Data intelligence enters the "deep water area", and data governance is the key