+ 2
Functional programming - Help
I'm just into the first lesson in the functional programming section and can't understand the first code, def apply_twice(func, arg): return func(func(arg)) def add_five(x): return x + 5 print(apply_twice(add_five, 10)) How did the result turn out 20 and what is #return func(func(arg)) Can anyone explain this in a simple way Thank you Have a great day!
2 Respostas
+ 5
The code is defining two functions: apply_twice and add_five. The apply_twice function takes two arguments, a function (func) and an argument (arg). It then calls the function twice, passing in the argument each time. The add_five function takes one argument (x) and adds 5 to it.
When you call apply_twice with add_five and 10 as arguments, it calls add_five twice with 10 as the argument each time. So the result is 10 + 5 + 5 = 20.
+ 3
im Reza thanks alot!!!!