def tupleVarArgs(arg1,arg2='defaultB',*theRest): 'display regular args and non-keywork variable args' print 'formal arg1:',arg1 print 'formal arg2:',arg2 for eachXtrArg in theRest: print 'another arg:',eachXtrArg >>> tupleVarArgs('abc') formal arg1: abc formal arg2: defaultB >>> tupleVarArgs(23,4.56) formal arg1: 23 formal arg2: 4.56 >>> tupleVarArgs('abc',123,'xyz',456.789) formal arg1: abc formal arg2: 123 another arg: xyz another arg: 456.789
def dictVarArgs(arg1,arg2='defaultB',**theRest): 'display regular args and non-keywork variable args' print 'formal arg1:',arg1 print 'formal arg2:',arg2 for eachXtrArg in theRest.keys(): print 'Xtra arg %s: %s'%\ (eachXtrArg,str(theRest[eachXtrArg])) >>> dictVarArgs(1111,745,c='test') formal arg1: 1111 formal arg2: 745 Xtra arg c: test >>> dictVarArgs(arg2='arg2',c=123,d='ddd',arg1='mystery') formal arg1: mystery formal arg2: arg2 Xtra arg c: 123 Xtra arg d: ddd >>> dictVarArgs('one',d=10,e='zoo',men=('freud','gaudi')) formal arg1: one formal arg2: defaultB Xtra arg men: ('freud', 'gaudi') Xtra arg e: zoo Xtra arg d: 10
def dictVarArgs(arg1,arg2='defaultB',*theRest2,**theRest): 'display regular args and non-keywork variable args' print 'formal arg1:',arg1 print 'formal arg2:',arg2 for eachXtrArg in theRest.keys(): print 'Xtra arg %s: %s'%\ (eachXtrArg,str(theRest[eachXtrArg])) for rest2 in theRest2: print 'Xtra2 arg %s:' % rest2 >>> dictVarArgs(1,theRest2='abc',theRest=['def','hjk']) formal arg1: 1 formal arg2: defaultB Xtra arg theRest: ['def', 'hjk'] Xtra arg theRest2: abc