How come when I type the following
eval("mult = lambda x,y: (x*y)")
I get this as an error? What’s going on?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
mult = lambda x,y: (x*y)
^
SyntaxError: invalid syntax
What am I doing wrong? If I enter the expression as is (no eval) I get no error, and can use mult to my hearts content.
You want to use exec instead of eval. I don’t know why you would want to do this though when you can just use
mult = lambda x,y : (x*y)