Search notes:

Python: exec

statement_1  = 'num = 42'
statement_2  = 'print(num)'
statements   = '''
num = num * 2
print(num)
'''

exec(statement_1)
exec(statement_2)
exec(statements )

See also

exec is applied to a statement while eval is applied to an expression.
Python: Built in functions

Index