当前位置:网站首页>Eval function, global, local variables
Eval function, global, local variables
2022-06-27 20:29:00 【LRJ-jonas】
eval() function :
a=10; print(eval("a+1"))eval Function will “ String text ” Change to code variable
stay Python in evel() The syntax format of the function is 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 and c Go to the dictionary respectively g And the dictionary t The value in , When globals and locals There are parameters in b You take locals The value in . therefore a=6,b=100,c=10. The running result is 116
application : You can use one line of code to implement the functions of the calculator print(eval(input(' Please enter '))).
shortcoming : But because it has the ability to convert strings into expressions for execution , So it can execute system commands . This can easily be used by people with ulterior motives to execute system commands , Delete key system files .
边栏推荐
猜你喜欢

Pointers and structs

本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献

Connection integration development theme month | drivers of enterprise master data governance

NVIDIA三件套环境配置

OpenSSL client programming: SSL session failure caused by an obscure function

数据库引擎

UE4:Build Configuration和Config的解释

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

Practice of combining rook CEPH and rainbow, a cloud native storage solution

花了6个月时间完成本科优秀毕业设计,我做了什么?
随机推荐
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
Linux系统ORACLE 19C OEM监控管理
Pfsense plus22.01 Chinese customized version release
I haven't thought about the source for some time. After upgrading to the latest version 24, the data encryption problem is repeatedly displayed
Logcli Loki command line tool
SQL报了一个不常见的错误,让新来的实习生懵了
Mass lucky hash game system development - conflict resolution (code analysis)
When developing digital collections, how should cultural and Museum institutions grasp the scale of public welfare and Commerce? How to ensure the security of cultural relics data?
Manage rust project through cargo
ABAP essays - interview memories hope that everyone's demand will not increase and the number of people will soar
linux系统笑着玩Oracle数据库多表查询-连接查询
Pyhton crawls Baidu library text and writes it into word document
SQL报了一个不常见的错误,让新来的实习生懵了
【bug】上传图片出现错误(413 Request Entity Too Large)
低代码开发平台是什么?为什么现在那么火?
ABAP随笔-通过api获取新冠数据
【STL编程】【竞赛常用】【part 2】
Data intelligence enters the "deep water area", and data governance is the key
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
移动低代码开发专题月 | 可视化开发 一键生成专业级源码