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 no
eval()
, as the name suggests, evaluates the passed argument.
raw_input()
is now input()
in python 3.x versions. So the most commonly found example for the use of eval()
is its use to provide the functionality that input()
provided in 2.x version of python.
raw_input returned the user-entered data as a string, while input evaluated the value of data entered and returned it.
eval(input("bla bla"))
thus replicates the functionality of input()
in 2.x, i.e., of evaluating the user-entered data.
In short: eval()
evaluates the arguments passed to it and hence eval('1 + 1')
returned 2.