Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Python's eval() do?

Tags:

python

eval

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?

like image 871
Billjk Avatar asked Feb 21 '12 19:02

Billjk


People also ask

What is the difference between eval () and INT () function?

eval evaluates any python code. int tries to convert any type to integer (float, bool, string ...). you got it.

What is the difference between eval and input function in Python?

eval evaluates a piece of code. input gets a string from user input. Therefore: eval(input()) evaluates whatever the user enters.


1 Answers

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 
like image 188
BYS2 Avatar answered Oct 13 '22 10:10

BYS2