0 votes
1 view
in Python by (47.8k points)

I've been looking at the dynamic evaluation of Python code, and come across the eval() and compile() functions, and the exec statement.

Can someone please explain the difference between eval and exec, and how the different modes of compile() fit in?

1 Answer

0 votes
by (107k points)

  1. The word exec is not an expression: When you work in Python 2.x it is a statement there, and in Python 3.x it is a function. Its work is to compile and evaluate the statement immediately.
  2. The word eval is a built-in function, it evaluates an expression and returns the value produced by that expression. 
  3. Whereas the word compile is a lower-level version of exec and eval. It returns a code object that can do it. 

Related questions

0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...