Python exec() FunctionPython Functions


The exec() function executes the specified Python code.

Example

#!/usr/bin/python3

exec('print("ABCD")')

exec('print("Hello")nprint("World")')

Output:

ABCD
Hello
World

Syntax

exec(object, globals, locals)

Parameters

Name Description
object A String, or a code object
globals A dictionary containing global parameters
locals A dictionary containing local parameters

Return Value

The method doesn’t return any values.

© 2021 Programtips.org, all rights reserved. Privacy Policy | Contact Us