Jan-03-2021, 02:13 PM
I do get it now. The flexibility of the code below. I can pass "any" function that has two parameters. Instead of changing the function arguments. It's just a little difficult to grasp at first. I'm not used to doing it this way.
This is a little off topic but, I think Python needs to restructure their namespacing. Like Javascript. Global, function and block. Just my 2 cents.
This is a little off topic but, I think Python needs to restructure their namespacing. Like Javascript. Global, function and block. Just my 2 cents.
(Dec-01-2020, 01:50 PM)muzikman Wrote: Thank you for your example. Yes, I understand it.
If I were to call these functions by name from the calcit function, I would have to change the code in that function. Instead of just assigning the new function outside the main function. Thank you everyone for your help.
(Nov-30-2020, 11:47 PM)jefsummers Wrote: It's a level of flexibility.
123456789101112131415def
multiply(a,b):
return
a
*
b
def
addit(a,b):
return
a
+
b
def
calcit(func,op1,op2):
return
func(op1,op2)
function
=
multiply
a
=
5
b
=
6
(calcit(function,a,b))
function
=
addit
(calcit(function,a,b))
Output:30 11