+ 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?

29th Jul 2016, 12:36 AM
sharper_than_learning_curve
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.
29th Jul 2016, 6:31 AM
RedAnt
RedAnt - avatar
+ 2
l=(lambda x,y:x*y)(2,5) print(l)
19th Nov 2016, 2:38 PM
Hetbo.net
Hetbo.net - avatar