1 Star 0 Fork 1

aliao/stdpython

forked from pish7/stdpython 
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
a04.py 492 Bytes
Copy Edit Raw Blame History
pish7 authored 2025-12-28 01:28 +08:00 . python
# exec 执行一系列 Python 语句
# 提供一个字典作为 exec 的存储空间,exec中创建的变量在存储在 namespace 中
namespace = {}
exec(
"""
x = 3
y = 4
z = x * y
""",
namespace,
)
print(namespace["z"]) # 12
# eval
# 计算用字符串表示的Python表达式的值
a = 2
b = 3
c = eval("a * b") # 计算并返回 python 表达式的值
print(c) # 6
namespace = {"a": 2, "b": 3} # 命令空间也可用于传值
c = eval("a * b", namespace)
print(c) # 6
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/aliaodc/stdpython.git
git@gitee.com:aliaodc/stdpython.git
aliaodc
stdpython
stdpython
master

Search