Python 执行字符串表达式函数(eval exec execfile)
来源:互联网 发布:换热量计算软件 编辑:程序博客网 时间:2024/06/12 18:52
仔细研读后学习了三个函数:
eval:计算字符串中的表达式
exec:执行字符串中的语句
execfile:用来执行一个文件
需注意的是,exec是一个语句,而eval()和execfile()则是内建built-in函数。
1
2
3
4
5
6
7
8
Python
2.7
.
2
(default, Jun
12
2011
,
15
:
08
:
59
) [MSC v.
1500
32
bit (Intel)] on win32
Type
"help"
,
"copyright"
,
"credits"
or
"license"
for
more information.
>>> x
=
1
>>>
print
eval
(
"x+1"
)
2
>>>
exec
"print 'http://blog.leniy.org/python-eval-exec-execfile.html'"
http:
/
/
blog.leniy.org
/
python
-
eval
-
exec
-
execfile
.html
>>>
同时,我们有时使用input输入一些数据,例如
1
2
3
4
>>>
input
(
"请输入:"
)
请输入:
1
+
2
*
*
3
9
>>>
其实这里的input也是eval的应用,等效于
1
2
3
4
>>>
eval
(
raw_input
(
"请输入:"
))
请输入:
1
+
2
*
*
3
9
>>>
0 0
- Python 执行字符串表达式函数(eval exec execfile)
- python exec/eval/execfile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- Python exec eval execfile compile 学习
- python中eval, exec, execfile,和compile
- python:exec eval execfile compile介绍
- Python 的exec, eval()和execfile()
- python:exec eval execfile compile介绍
- python:exec eval execfile compile介绍
- python中eval, exec, execfile,和compile
- 在Oracle VM VirtualBox下安装fedora20
- Python基础10 反过头来看看
- Gradle version 1.10 is required. Current version is 2.0
- 找到程序或动态库所依赖的所有动态库
- eclipse中创建android项目时,设定minimum required SDK、TargetSDK和Compile SDK有什么要求
- Python 执行字符串表达式函数(eval exec execfile)
- 使用ant编译Android工程(二)
- Android 百度地图最新SDK v3.2.0和Android定位SDK:v5.0应用(2)
- 设计模式----策略模式(一)
- [LeetCode]171.Excel Sheet Column Number
- Python进阶01 词典
- Python进阶02 文本文件的输入输出
- C++ 容器及选用总结
- iOS开发之打包上传到App Store——(一)各种证书的理解