Parameters of Python anonymous function

def make_fun (n):

return lambda x:x+n

f=make_fun (15)
print (f (5)
Please see the above code. What"s going on in the anonymous function? it doesn"t pass a parameter, and the code can run. The final output is 20

.

you can think of lambda as a dynamic function, and x is the argument (independent variable) of this function.
make_fun (15) is equivalent to returning a function of def fun (x): return x < 15 . Call this function, pass 5 as a parameter, and return 5 "15" 20

.
Menu