Python exe() function
Python exe() function
The exec() function in Python executes the specified Python code and accepts large blocks of code. It supports dynamic execution of Python code where the object must be either a string or a code object.
Syntax:
exec(object[,globals[,locals]])
Parameter
expression: This parameter represents a String, that will be evaluated as Python code
globals: It is an optional parameter that represents a dictionary containing global parameters
locals: It is also an optional parameter that represents a dictionary containing local parameters
Return
This function returns the result of the evaluated expression
Example 1
# Python Program explaining # exec() function x = 'print(52365)' exec(x)
Output
52365
Example 2
# Python Program explaining # exec() function x = 11 print(exec('x==11')) print(exec('x+2'))
Output
None None