Exec() method in Python Built in Function
Exec method in built in function executes a program which is either a string or a code object.
Syntax:
exec(object[, globals[, locals]])
Parameter
exec has three parameters.
- Expression:the parsed or the resolved string is entered and evaluated as a python expression.
- Locals:this parameter is used a mapping object. Dictionary is an commonly used mapping object.
- Globals: It a dictionary.
Example-1:
x = 'name = "Tulip season in Ottawa"\nprint(name)' exec(x)
Output:

Example-2:
x = 'a = 8\nb=10\nprint("add of =", a+b)'
exec(x)
Output:

Example-3:
program = input('Enter a program:')
exec(program)
Output:
