+ 3
I dont get it
so i saw this on functions 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)) i dont get what does func do
6 Respostas
+ 12
func represents the formal parameter for functions.
In this case, function add was used in the parameters, hence function do_twice returns:
add(add(5, 10), add(5, 10))
resulting in return value of 30.
+ 12
@Meharban You can replace 'func' with any other legit variable name you prefer.
+ 3
@Hasty, can we use any other variable as parameter instaed of func?
+ 1
thanks so much :)
+ 1
thanks@Hasty
0
You can see it as a flag. It is used to receive which function should be used