+ 1
please explain the code given in description..
def apply_twice(func, arg): return func(func(arg)) def add_five(x): return x + 5 print(apply_twice(add_five, 10))
5 Respostas
+ 2
apply_twice call recursively 2 times the add_five function... The first time, it have like param 10 get as result 15, then this value is passed as param for 2nd execution that return 20 that its returned from apply_twice call
+ 2
Priyanshu Ghatiya, it is better for your progress to do this yourself in your head or on a piece of paper!
The program starts with the last line.
And the content of parentheses is executed from the innermost set going outwards.
0
can you explain me more deeply i does not get it.Please explain the code line by line
0
First two are both functions that won't execute unless called
In the last line the code is trying to print the output that it receives from apply twice function so it is called and will now execute and it takes two arguments add five and 10
So apply twice calls the function once that is the add_five(10) which returns 15 .
Next time add_five is called
Return add_five(15) which returns output to be printed that is 20
0
Now that was what the requester was looking for. Well done! Thanks for taking the time to explain the code line-for-line.