eval()exec()and compile(the eval(str [,globals [,locals]]function executes an expression string and returns the result here' an examplea eval(' *math sin( + 'similarlythe exec(str [globals [locals]]function executes string containing arbitrary python code the code supplied to exec(is executed as if the code actually appeared in place of the exec operation here' an examplea [ exec("for in aprint( )"one caution with exec is that in python exec is actually defined as statement thusin legacy codeyou might see statements invoking exec without the surrounding parenthesessuch as exec "for in aprint ialthough this still works in python it breaks in python modern programs should use exec(as function both of these functions execute within the namespace of the caller (which is used to resolve any symbols that appear within string or fileoptionallyeval(and exec(can accept one or two mapping objects that serve as the global and local namespaces for the code to be executedrespectively here' an exampleglobals {' ' ' ' 'birds'['parrot''swallow''albatross'locals execute using the above dictionaries as the global and local namespace eval(" "globalslocalsexec("for in birdsprint( )"globalslocalsif you omit one or both namespacesthe current values of the global and local namespaces are used alsodue to issues related to nested scopesthe use of exec(inside of function body may result in syntaxerror exception if that function also contains nested function definitions or uses the lambda operator when string is passed to exec(or eval(the parser first compiles it into bytecode because this process is expensiveit may be better to precompile the code and reuse the bytecode on subsequent calls if the code will be executed multiple times the compile(str,filename,kindfunction compiles string into bytecode in which str is string containing the code to be compiled and filename is the file in which the string is defined (for use in traceback generationthe kind argument specifies the type of code being compiled--'singlefor single statement'execfor set of statementsor 'evalfor an expression the code object returned by the compile(function can also be passed to the eval(function and exec(statement here' an examples "for in range( , )print( ) compile( ,'','exec'compile into code object exec(cexecute it " yc compile( '''eval'result eval( compile into an expression execute it lib fl ff