0
What does add do here? Why is it here?
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))
3 Respostas
+ 3
This is more of a demonstration of what can be done than a useful piece of code. It demonstrates that you can not only pass a string, number, list, etc. to a function, but you can also pass a function name to it. add() is just a very simple function that is being used to demonstrate this
In do_twice(), the func parameter becomes the name of the function passed to it, in this example, add(). So the return line becomes
return add(add(a, b), add(a, b))
which is
return add(15, 15)
so it returns 30.
Again, nothing special about add() just a simple function to demonstrate what's possible.
0
Hello 3.14159265358, its easy, in my code explain u.
https://code.sololearn.com/cqGZC4Ppr5jB/?ref=app