17. Dynamic Code Execution
Python allows executing code dynamically with exec and eval.
Example with eval
expr = "2 + 3 * 4"
print(eval(expr)) # 14
Example with exec
code = "x = 10\ny = 20\nprint(x + y)"
exec(code)
Caution
Dynamic execution is powerful but can be unsafe with untrusted input.
Wrap-Up
Use exec and eval carefully, mainly in controlled environments.