I want to write a function that has a default value that is another input of the function. I’d like something like this:
def pythag_thm(a, b=a):
return (a**2 + b**2)**.5
but I get a NameError: name 'a' is not defined. I realize I could do something like:
def pythag_thm(a, b=False):
if b==False:
return (a**2 + a**2)**.5
else:
return (a**2 + b**2)**.5
but this does not seem very ‘pythonic’. Is there a clean way to do this? Am I just thinking of this in the wrong way?
What people usually do is