+ 1
How to work it
def apply_twice(func, arg): return func(func(arg)) def add_five(x): return x + 5 print(apply_twice(add_five, 10)) How to work it please help me.....
2 Respuestas
+ 5
It works very well...!
when you called the apply_twice function under a print function, it took it's arguments add_five and 10 to the function body.
now, let's go to the apply_twice function. 'func' and 'arg' are now changed to 'add_five' and '10' respectively. The return statement now turned like this,
return add_five(add_five(10))
add_five(10) returns 15 from the second function.
then we have
return add_five(15)
and finally it returns 20.
+ 2
do you see, what is func and what is arg?