return result from exec python

the_code = '''
a = 1
b = 2
return_me = a + b
'''

loc = {}
exec(the_code, globals(), loc)
return_workaround = loc['return_me']
print(return_workaround)  # 3

Here is what the above code is Doing:
1. The first argument to exec is the code to be executed.
2. The second argument is the global namespace.
3. The third argument is the local namespace.
4. The code is executed.
5. The return value is stored in the local namespace.
6. The return value is retrieved from the local namespace.