0

Functions in python

can anyone explain please, why the result is 9 and how does func(x)(x) an func1(x)(x) works? def func(x): return lambda y: (x + y + 1) def func1(x): return lambda y : (func(x)(x)+y+1) print(func1(3)(1))

17th May 2021, 1:02 PM
Zohrab Mammadov
Zohrab Mammadov - avatar
3 odpowiedzi
17th May 2021, 1:17 PM
TOLUENE
TOLUENE - avatar
+ 2
func1(3)(1) Here func1(3) returns a lambda, where x is 3, and y is 1. We pass 1 to the parameter of the lambda returned by func1(3). -> lambda y: func(3)(3)+1+1 func(3)(3) works as same as func1(3)(1). Here first (3) is for the func. The second (3) is for the lambda returned by func(3). func(3)(3) -> 3+3+1 So func(3)(3)+1+1 = 3+3+1+1+1 = 9
17th May 2021, 1:17 PM
你知道規則,我也是
你知道規則,我也是 - avatar
0
thanks a lot for your help SAYED🇧🇩🇵🇸 and CarrieForle
17th May 2021, 1:36 PM
Zohrab Mammadov
Zohrab Mammadov - avatar