How do you call a lambda function?

None of the lambda function examples in this lesson call on a lambda function with specific inputs to generate specific outputs like you would with a traditional function definition. When I try doing this, I don’t get what I expect. For example, this lesson defines a function called multiply() using traditional syntax…

def multiply(a, b):
    return a * b

… which I can call as follows…

…and I get the output 6, which is expected.

But if I try something similar with a lambda function…

a = 2
b = 3
multiply = lambda a, b : a * b
multiply

…I get something different…

<function __main__.<lambda>(a, b)>

It seems like a lambda function is not made to be called upon directly to generate an output. It’s made to be passed as a variable so some other function can call it to make an output?

In the lambda function above, no name is assigned as in traditional function. Only a variable multiply is assigned which simply returns function object.
If you print traditional multiply function it will produce <function multiply at 0x7fe3cafb18c8>
and if we print lambda function <function <lambda> at 0x7fe3ccc69730>
Look at the difference of function name in both . One is multiply whereas other is <lambda> ie. Anonymous Function with no name
So call lambda function as like the traditional function

Just add (), the sugar for __call__ to multiply. so you call it like multiply(), same syntax as the multiply defined the non lambda way def multiply.

Practically I don’t see much value in lambda, they are 1-liners putting together the function signature, body, and return statement, making it much harder to read at a glance than the def way.

That’s good to know. Thanks!

That clears things up a lot. Thanks!