Well I did try to read about Lambda functions but did not get across any link which explains few questions about its flow and the way it is handled by python interpretor or may be I could not understand it properly. I have few question, please can somebody clarify them for me. Here is the code :
def f1(n):
print 'in f1, value is : ', n
return lambda x: x+n
if __name__ == '__main__':
f= f1(100)
print f(1)
print f(3)
print f1(10)
print f(5)
print type(f1)
The output being :
in f1, value is : 100
101
103
in f1, value is : 10
<function <lambda> at 0x019C66B0>
105
<type 'function'>
My question is :
- For
f(1)
andf(3)
whyprint
statement was not called and when we calledf1(100)
why lambda statement was not compiled. - What is the relation between
x
andn
in functionf1
. - I thought
f(5)
will 15 ( 10 + 5) - Please explain
print f1(10)
- Also, please let me know what is
lambda x:
means here, is that x name of this block? please explain.
Thanks all.