+ 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))
2 odpowiedzi
+ 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
+ 3
Thank you! Jayakrishna, your answer is really helpful for me.