educative.io

Educative

Why don't these two give me the same output?

calc_function = lambda n1, n2 : n1*n2
print (calc_function (10,20))

print (lambda n1, n2: n1*n2 (10, 20))

Why don’t I get the exact same output for both these functions?

This is what I get:
200
<function at 0x7fda25c91f28>

Hi, @Aditya7 hope you are doing well.

You are trying to directly call a function by passing values that violate its syntax(lambda). For it to work, first you have to assign it and then pass the values to the assigned variable, which you are following in the first approach.

Shaheryaar Kamal | Technical Content Engineer

Ok. Also found a simpler way to do it - just enclosed the lambda in parenthesis.