Search notes:

Python: compile

src = '''
num =  42
txt = 'Hello world'
print(f'num = {num}, txt = {txt}')
'''

code = compile(src, '?', 'exec')

print(type(code))
#
# <class 'code'>

eval(code)
#
# num = 42, txt = Hello world
Github repository about-python, path: /built-in/functions/compile/exec.py

See also

eval
Python: Built in functions

Index