0
Functions
Please explain how the following results (30) are coming? Total example page is given copped from the web. ................................. Functions can also be used as arguments of other functions. 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)) Try It Yourself Result: >>> 30 >>> As you can see, the function do_twice takes a function as its argument and calls it in its body.
2 Answers
+ 5
You are giving add to the function do twice.
So do_twice actually calculates
add(add(5, 10) + add(5,10))
meaning
add(15, 15)
->
30
+ 1
Thank you HonFu