From 6ea8efa96f101f738c027fba29ef405079237c34 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Thu, 16 Jul 2009 08:44:36 -0400 Subject: [PATCH] clarify exec() vs. eval() --- porting-code-to-python-3-with-2to3.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html index 5b5704b..8f98b49 100644 --- a/porting-code-to-python-3-with-2to3.html +++ b/porting-code-to-python-3-with-2to3.html @@ -611,7 +611,7 @@ reduce(a, b, c)

exec statement

-

Just as the print statement became a function in Python 3, so too has the exec statement. The exec() function takes a string which contains arbitrary Python code and executes it as if it were just another statement or expression. +

Just as the print statement became a function in Python 3, so too has the exec statement. The exec() function takes a string which contains arbitrary Python code and executes it as if it were just another statement or expression. exec() is like eval(), but even more powerful and evil. The eval() function can only evaluate a single expression, but exec() can execute multiple statements, imports, function declarations — essentially an entire Python program in a string.
Notes