+ 7

Can I use lambda to evaluate x for user given functions??

8th Apr 2017, 8:03 AM
Prabhakar Dev
Prabhakar Dev - avatar
5 ответов
+ 9
yup use eval to evaluate the given user input f=eval(input("Enter the function: ")) # input: lambda x:x*x print(f(8)) #outputs 64
8th Apr 2017, 8:14 AM
Burey
Burey - avatar
+ 6
print("Thanks Burey") print("Needed that for something")
8th Apr 2017, 8:32 AM
Prabhakar Dev
Prabhakar Dev - avatar
+ 5
you mean something like this? def sqr(x): return x*x f=lambda x:sqr(x) print(f(2))
8th Apr 2017, 8:09 AM
Burey
Burey - avatar
+ 5
no problem :) happy to help
8th Apr 2017, 8:33 AM
Burey
Burey - avatar
+ 4
nope x=input("Enter the function: ") y=lambda z: x print(y(8)) something like that
8th Apr 2017, 8:11 AM
Prabhakar Dev
Prabhakar Dev - avatar