0

functions

Can someone please explain the code. i don't want to move forward without fully understanding 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))

28th Jun 2017, 7:48 AM
Leroy Williams
Leroy Williams - avatar
3 Réponses
+ 4
Does this help? do_twice(add, a, b) do_twice(add, 5, 10) add(add(5, 10), add(5, 10)) add(5 + 10, 5 + 10) add(15, 15) 15 + 15 30
28th Jun 2017, 8:10 AM
Igor B
Igor B - avatar
+ 2
(10 + 5) + (10 + 5) = 30
28th Jun 2017, 8:00 AM
Oscar Albornoz
Oscar Albornoz - avatar
0
do_twice function is called first here add is func (understand formal parameters and actual parameters) so in return statement of do_twice function,add function will be called twice
28th Jun 2017, 9:17 AM
Sandesh
Sandesh - avatar