Python exec() FunctionThe python exec() function is used for the dynamic execution of Python program which can either be a string or object code and it accepts large blocks of code, unlike the eval() function which only accepts a single expression. Signatureexec(object, globals, locals) Parametersobject - It should be either string or code object. globals (optional) - It is used to specify global functions. locals (optional) - It is used to specify local functions. Let's see some examples of exec() function which are given below: Python exec() Function Example 1This example shows working of exec() function. Output: True 9 Python exec() Function Example 2This example shows exec() dynamic code execution Output: Enter Code Snippet to execute: print(sqrt(16)) 4.0 Enter Code Snippet to execute: print(min(2,1)) 1 Done Next TopicPython Built in Functions |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India