Calling Functions with Variable Argument Objects : Varible length parameter « Function « Python Tutorial






def newfoo(arg1, arg2, *nkw, **kw):
    print 'arg1 is:', arg1
    print 'arg2 is:', arg2
    for eachNKW in nkw:
        print 'additional non-keyword arg:', eachNKW
    for eachKW in kw.keys():
        print "additional keyword arg '%s': %s" % (eachKW, kw[eachKW])

newfoo(10, 20, 30, 40, foo=50, bar=60)
newfoo(2, 4, *(6, 8), **{'foo': 10, 'bar': 12})
aTuple = (6, 7, 8)
aDict = {'z': 9}
newfoo(1, 2, 3, x=4, y=5, *aTuple, **aDict)








10.5.Varible length parameter
10.5.1.Varible length parameter
10.5.2.variable length arguments
10.5.3.Keyword Variable Arguments (Dictionary)
10.5.4.Both keyword and non-keyword variable arguments may be used in the same function as long as the keyword dictionary is last
10.5.5.Calling Functions with Variable Argument Objects
10.5.6.** works for keyword arguments: it collects them into a new dictionary,
10.5.7.A dictionary containing all keyword arguments whose keyword doesn't correspond to a formal parameter
10.5.8.*args and **kwargs example