Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It's good to know the exec function - a powerful tool for "code generation":

sage: for k in range(1001):                                             
....:     exec("f_%d = lambda x:sin(%d*x)"%(k,k))
sage: f_11(2)

I don't know what are the risks of using it (sometimes with great power comes great nagging about "bad programming habits", the most famous example is 'goto' commands).

"exec" also has a less powerful brother "eval", which does not help for your needs, but is also good to know (being less powerful he is probably less dangerous).