非关键字可变长参数(元组)
要特别注意默认参数的不同
def tupleVarArgs(arg1, arg2='defaultB', *theRest): 'display regular args and non-keyword variable args' print 'formal arg 1:', arg1 print 'formal arg 2:', arg1 for eachXtrArg in theRest: print 'another arg:', eachXtrArg>>> tupleVarArgs('abc', 123, 'xyz', 456.789)formal arg 1: abcformal arg 2: 123 # 注意默认参数another arg: xyzanother arg: 456.789
关键字变量参数(字典)
def dictVarArgs(arg1, arg2='defaultB', **theRest): 'display 2 regular args and keyword 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('one', d=10, e='zoo', men=('freud', 'gaudi'))formal arg1: oneformal arg2: defaultB # 注意默认参数Xtra arg men: ('freud', 'gaudi')Xtra arg d: 10Xtra arg e: zoo