Turn strings into code: eval and exec

eval(s) evaluates a Python expression s
eval('sin(1.2) + 3.1**8')
exec(s) executes the string s as Python code
s = 'x = 3; y = sin(1.2*x) + x**8'
exec(s)
Main application: get Python expressions from a GUI (no need to parse mathematical expressions if they follow the Python syntax!), build tailored code at run-time depending on input to the script

previousnexttable of contents