I want to have the following heading where the default value of a parameter depends on another parameter:
def function2(x,l=0,r=len(x)-1)
This obviously returns an error. Is there any way to go around this?
Thank you
I want to have the following heading where the default value of a parameter depends on another parameter:
def function2(x,l=0,r=len(x)-1)
This obviously returns an error. Is there any way to go around this?
Thank you
This workaround maybe can help:
def function2(x, l=0, r=None):
if r is None:
r = len(x) - 1
...
This will set r
to len(x) - 1
only when r
is not set, i.e:
function2(x='hi', l=0) # r will take value len(x) - 1
function2(x='hi', l=0, r=5) # r will take value 5
I am not sure if this solution will completely help you.
If a variable depends on another input variable it might be interesting to do something like:
def function2(x,l=0):
r = len(x) - 1
...