0
python function as objects
I totaly lost my understanding in the second function please can someone explain to me what the second function do and how def add(x, y): return x + y def do_twice(func, x, y): return func(func(x, y), func(x, y)) a = 5 b = 10 print(do_twice(add, a, b))
2 ответов
+ 3
In this code, the second function gets 3 arguments.
func = add
x = 5
y = 10
Therefore, the second function returns
add(add(5,10), add(5,10))
and, the first function return
add(15, 15) ---> 30
0
The inner funcs in the return statement are the arguments for the outer func, and thats why it is done twice. It is one of the challenges. I could be wrong.