# Is using except TypeError the right way to do this? [closed]

I have some code that uses a lambda to enhance the functionality. For backward compatibility reasons, this lambda can take one or two arguments. To handle these cases, I now use except TypeError to differentiate in the calls:

# This should work for both these cases:
# l = lambda x: x+2
# l = lambda x,y: x+y

try:
value = l(10)
except TypeError:
value = l(10, 20)


This works, but could this be made better? What if I decide to have three or more arguments for example?

What your existing code shows is that you'd like the second argument (y) to be optional with a default value of 2 (or is it 20?). Therefore, you could do:
def l(x, y=2):