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?
2 Respostas
+ 2
Check this cool piece by AJ Anant out:
https://code.sololearn.com/cgfonDJu8pH0/?ref=app
+ 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 ,