0
Code Function as object
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)) explain<<do_twice>>>
1 Answer
+ 4
So everything here starts with 'print(do_twice(add, a, b))'
And then do_twice replaces variables in return statement and it looks like this 'add(add(a, b), add(a, b))'
After running both inside add(a, b) funcs this outside func becomes add(15, 15)
So then do_twice func returns 30, which is then the result
Hope this is a good explanation(you also have some explanations in comment section of the lesson)