1 def test(a, b, c, d): 2 print a, b, c, d 3 return "->".join([str(a), str(b), str(c), str(d)]) 4 5 def test1(a, b, c, d): 6 print a, b, c, d 7 return "->".join([str(a), str(b), str(c), str(d)]) 8 9 10 def test2(*args, **kwargs): 11 print "args: " + str(args) 12 print "kwargs: " + str(kwargs) 13 14 def main(): 15 param = [1,2,3,4] 16 param1 = { 17 "a":1, 18 "b":2, 19 "c":3, 20 "d":4, 21 } 22 23 print test(*param) 24 print test1(**param1) 25 print test2(*param, **param1) 26 27 if __name__ == '__main__': 28 main()
test_args.py 1 2 3 4 1->2->3->4 1 2 3 4 1->2->3->4 args: (1, 2, 3, 4) kwargs: {'a': 1, 'c': 3, 'b': 2, 'd': 4} None