Python的eval()有什么作用? [英] What does Python's eval() do?

查看:85
本文介绍了Python的eval()有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我用Python阅读的书中,它一直使用代码 eval(input('blah'))

In the book that I am reading on Python, it keeps using the code eval(input('blah'))

我阅读了文档,并且我理解了它,但是我仍然看不到它如何更改 input()函数。

I read the documentation, and I understand it, but I still do not see how it changes the input() function.

它是做什么的?有人可以解释吗?

What does it do? Can someone explain?

推荐答案

eval函数允许Python程序在其内部运行Python代码。

The eval function lets a Python program run Python code within itself.

评估示例(交互式外壳):

eval example (interactive shell):

>>> x = 1
>>> eval('x + 1')
2
>>> eval('x')
1

这篇关于Python的eval()有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆