+ 1
Lambda issue
Please help in describing below code: a = (lambda x: x**3)((lambda x: x+2)(1)) print(a) Output is : 27
4 Answers
+ 6
The above code can also be written like so:
b = (lambda x: x+2)(1)
a = (lambda x: x**3)(b)
-----------------------
Think of the first line like this:
def func(x):
return x + 2
b = func(1)
Here, we are passing an argument of 1 to 'func', which returns the value of 1 +2, which means b is now equal to 3.
-----------------------
In the same way, the second line can also be written like this:
def func2(x):
return x**3
a = func2(b)
Just like the first line, we are passing the value of b to func2, which returns b**3, that is 3**3 which finally results in 27.
Let me know if I can clear anything up :)
+ 2
that's not an issue,
lambda x: x**3 took ((lambda x: x+2)(1)) as it's argument, these 3 steps should explain:
a = (lambda x: x**3)((lambda x: x+2)(1))
a = (lamda x: x**3)(3)
a = 27
+ 1
honestly a lot of the problem is we are missing the original programmers notes in code on the screen. if the programmer codes correctly notating their work a large amount of confusion would be taken out... seems like WET work.
- 1
Thank you Just A Rather Ridiculously Long Username and Seb TheS