im trying to learn python online and am currently on lambda functions but I cant understand this code. Got the code from w3 school.
def myfunc(n):
return lambda a : a * n
mydoubler = myfunc(2)
print(mydoubler(11))
Ans: 22
I understand the myfunc(n)
, but isn't lambda
supposed to have a func written in front of it like func(n) = lambda n: n+5
or something? Or is the function in front of it just the func(n)
? And I understand a*n = 2* 11
in this example but I don't understand how 2
and 11
slots into a
and n
for this example. Any help or explanation will be very much appreciated.
Thanks!