What does Python's eval() do?

Billjk picture Billjk · Feb 21, 2012 · Viewed 457.5k times · Source

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

BYS2 picture BYS2 · Feb 21, 2012

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