+ 1

Can anyone explain this below python code to me , as I am beginner I am not able to understand it

def add(x, y): return 55 def do_twice(func, x, y): return func(func(x, y), func(x, y)) a = 5 b = 10 print(do_twice(add, a, b))

19th Nov 2022, 3:28 PM
Swapnil Kuwar
Swapnil Kuwar - avatar
2 Respostas
+ 4
'add' is function in your code. In entity in a python program has a reference in a memory. So you are passing 'add' function reference to do_twice function as parameter so 'func' is a alias name to 'add' function just. Now statement works as => return add( add(x, y) , add(x, y) ) => return add ( 55 , 55 ) => return 55
19th Nov 2022, 3:36 PM
Jayakrishna 🇮🇳
+ 3
Thank you! Jayakrishna, your answer is really helpful for me.
19th Nov 2022, 4:03 PM
Swapnil Kuwar
Swapnil Kuwar - avatar