How can I make the default value of an argument depend on another argument (in Python)?
The language doesn't support such syntax.
The usual workaround for these situations(*) is to use a default value which is not a valid input.
def func(n=5.0, delta=None):
if delta is None:
delta = n/10
(*) Similar problems arise when the default value is mutable.
You can't do it in the function definition line itself, you need to do it in the body of the function:
def func(n=5.0,delta=None):
if delta is None:
delta = n/10
You could do:
def func(n=5.0, delta=None):
if delta is None:
delta = n / 10
...