I have 2 functions: f, g:
f = lambda x:x**2
g = lambda x:x**3
I am trying to create new functions using the functions above, like this:
new_f, new_g = [lambda x:function(x)+30 for function in (f, g)]
When I run:
print(new_f(3))
print(new_g(3))
I expect:
39
57
but the actual output is:
57
57
With a little bit of debugging:
ids = [lambda: id(function) for function in (f, g)]
ids[0]() == ids[1]()
returns True.
But:
ids = [id(function) for function in (f, g)]
ids[0] == ids[1]
Returns False.
Why is lambda behaving this way?