codeObejct = compile(codeInString, 'sumstring', 'exec')
exec(codeObejct)
Run the program, the result is:
sum = 11
In the above example, the source here is a normal string, filename is sumstring, mode is exec after conversion, you can use the exec () function to call the resulting code object.
You can see a list of built-in Python functions and don't forget to do Python exercises to reinforce your knowledge.
Previous lesson: complex () function in Python
Next article: Function delattr () in Python