0

why is this repeated multiple times everywhere?

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)) Here, why do I have to keep writing 'func' everywhere and what is its' purpose? This is the one thing I'm not getting at all. Can anyone explain in detail?

15th Jul 2020, 10:13 AM
Faizan Ahmed
2 odpowiedzi
15th Jul 2020, 11:22 AM
Tomiwa Joseph
Tomiwa Joseph - avatar
+ 1
func is just a parameter name like x and y ,you could use just any other name ,it doesn't matter ,func makes it kinda intuitive that a function is going to be passed to this parameter , it has no other purpose other than being a function parameter,you could even name it a or b or whatever ,
15th Jul 2020, 11:03 AM
Abhay
Abhay - avatar