I think we should make a distinction between default values ββand passing to arbitrary argument / key-value pairs. The behavior without default values ββis the same:
def f(ae,*args, **kwargs): print 'ae = ', ae print 'args = ', args print 'kwargs = ', kwargs
The way we wrote this means that the first argument is passed to f in the args tuple, i.e. f(1,2,3,a=1,b=2) (the sequence goes into explicit arguments, * args, ** kwargs .) Here: ae = 1, args = (2,3), kwargs = {'a': 1, 'b': 2} .
If we try to pass in f(1,2,3,a=1,ae=3) , we will throw a TypeError: f() got multiple values for keyword argument 'ae' , since the value ae tries to be changed twice.
.
One way: only install ae , if it is explicitly set, we can (after the def line):
def g(*args, **kwargs): kwargs, kwargs_temp = {"ae": 9}, kwargs kwargs.update(kwargs_temp) #merge kwargs into default dictionary
and this time g(1,2,3,a=1,ae=3) sets args=(1,2,3), kwargs={a=1,ae=3} .
However, I suspect this is not the best practice ...