+ 1
How to pass multiple args to lambda function inline?
print (lambda x, y : x * y, (2, 10)) doesn't work. But following works: l = lambda x, y : x * y print(l(2, 10)) So while passing lambda to other function, we can pass only one argument? Essential for multiple arguments, lambda loses its conciseness? Is that correct understanding?
2 odpowiedzi
+ 4
you can pass multiple arguments to lambda function like this:
print((lambda x,y:x*y)(2,10))
but there is no real reason to do that because you can just write print(2*10) or whatever is the body of your lambda function. and keep in mind that if you supply arguments to the lambda function, then you are passing only it's return value to the function, not the lambda function itself.
+ 2
l=(lambda x,y:x*y)(2,5)
print(l)