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?
eval evaluates any python code. int tries to convert any type to integer (float, bool, string ...). you got it.
eval evaluates a piece of code. input gets a string from user input. Therefore: eval(input()) evaluates whatever the user enters.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With