python function as objects | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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))

18th May 2017, 11:30 AM
Majid Hussein
Majid Hussein - avatar
2 Respostas
+ 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
18th May 2017, 1:32 PM
Suyasa
Suyasa - avatar
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.
18th May 2017, 11:40 AM
Paul
Paul - avatar