python中exec()函数如何执行表达式?
python中exec()函数如何执行表达式?
1、python中exec()函数
把一个字符串当成一个表达式来执行,不返回结果
使用语法
exec(string_code,globals=None,locals=None)
2、python中exec()函数执行表达式实例:
x=100
y=200
#执行x+y
#z=x+y
z1=x+y
z2=eval("x+y")
print(z1)
print(z2)
输出
300
300
一定要注意字符串中引号的写法和比对exec执行结果和代码执行结果哦~更多Python学习教程请关注IT培训机构:千锋教育。

猜你喜欢LIKE
相关推荐HOT
更多>>
python中mat是什么意思?
python中mat是什么意思?本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。python的numpy库提供矩阵运算的功能,因此我们在需要矩阵运...详情>>
2023-11-10 23:22:48
python上下文管理的使用场景
python上下文管理的使用场景本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、上下文管理的使用场景凡是要在代码块前后插入代码的...详情>>
2023-11-10 20:07:44
python常量折叠是什么
python常量折叠是什么1、概念所谓常量折叠,指的是在编译时就查找并计算常量表达式,而不是在运行时再对其进行计算,从而会使运行时更加精简和...详情>>
2023-11-10 19:11:50
pythonTCP与UDP的不同点分析
python中TCP与UDP的不同点分析(推荐操作系统:windows7系统、Python3.9.1、DELLG3电脑。)1、不同点面向连接(确认有创建三方交握,连接已创建才...详情>>
2023-11-10 18:16:05热门推荐
技术干货






