python - Using one function as an optional argument in another function -
say i've got function (a simple function point across):
def f(x): if x: return(true) return(false)
now want use function optional argument in function, e.g. tried this:
def g(x, f_out = f(x)): return(f_out)
so if did g(1)
output should true
, , if did g(0)
want output false
, f(0)
false
, f_out
false
.
when try though, f_out
true
regardless of x
. how can make such function f
called when getting value f_out
?
the code i'm using principle on more complicated it's same idea; have optional argument in function1
calls different function2
parameters parameters in function1
, e.g. x
in example. (sorry i'm aware that's perhaps unclear way of explaining.)
you're calling function f_out
in declaration. want pass function parameter, , call inside g
:
def g(x, f_out=f): return f_out(x)
Comments
Post a Comment