How can I make the default value of an argument depend on another argument (in Python)?
arguments, function, python
Solution
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.
Problem
For instance, I want: ``` def func(n=5.0,delta=n/10): ``` If the user has specified a delta, use it. If not, use a value that depends on n. Is this possible?