Billjk Billjk - 4 months ago 13
Python Question

What does Python's eval() do?

In the book that I am reading on Python, it keeps using the code

eval(input('blah'))


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?

Answer

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