In python, variables are names mapped to values, not the values ββthemselves (everything is a reference). In addition, you can think of lambda as storing text that can be appreciated. Below is illustrated
a = 2 f = lambda x: a*x f(2)
This should clarify why you are getting infinite recursion.
In answer to your question about recursion, here is a small hack that could do
g = lambda x, n: n > 0 and g(x, n-1)**2 or x
Then g(2,3) will be (((2)^2)^2)^2 = 256 .
source share