I have this:
>>> a = lambda : lambda x : x * x
This gives me a constant address every time:
>>> a
<function <lambda> at 0x7f22769e76e0>
>>> a
<function <lambda> at 0x7f22769e76e0>
>>> a
<function <lambda> at 0x7f22769e76e0>
However this does not. Why so?
Also notice it gives only two addresses ? Why so?
Is the inner lambda function being created on the fly and returned every time on calling a()
? Was it not created when a was declared?
>>> a()
<function <lambda> at 0x7f22769e7320>
>>> a()
<function <lambda> at 0x7f22769e75f0>
>>> a()
<function <lambda> at 0x7f22769e7320>
>>> a()
<function <lambda> at 0x7f22769e75f0>