0
Python Lambdas: Can we create a lambda function which involves more than one variable?
A basic implementation of python lambda is: print((lambda x: x**2 + 5*x + 4) (-4)) When I form an expression like this, what happens is: print((lambda x,y: x^4 - y^4 + 4*x*y)(-4)(-5)) Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> print((lambda x,y: x^4 - y^4 + 4*x*y)(-4)(-5)) TypeError: <lambda>() missing 1 required positional argument: 'y' How do I use lambda for more than one variable?
5 Réponses
+ 2
Yes. Just put all arguments in a tuple 👌
+ 5
You're welcome ☺️👍
+ 4
print((lambda x,y: x^4 - y^4 + 4*x*y)(-4, -5))
+ 1
Thanks a lot!
so, if an equation involves n number of variables, I can put it in the above format & get the code run, right?
+ 1
Thanks a lot for your prompt responses. Very rare across the internet. This makes the Sololearn community, one of it's kind!