An alternative to other suggestions is to use the kwargs parameter, and then do something like this:
def func(a, **kwargs): if 'b' in kwargs: print 'b was passed in' b = kwargs['b'] else: print 'b was not passed in' b = 100 return a + b a = 50 func(a) func(a, b = 100)
Output:
b was not passed in 150 b was passed in 150
Since kwargs is a dictionary containing all optional parameters, you can examine this dictionary to determine what was / was not passed.
You can make search b more efficient, rather than searching kwargs twice if necessary.
source share