python里面有两个比较有特色的函数入参,*和**,按照习惯,一般命名为:
def func(*args, **kwargs): pass
<pre name="code" class="python">def func_a(**kwargs): print kwargs a = {"key": "value"} func_a(a) #func_a() takes exactly 0 arguments (1 given) func_a(*a) #func_a() takes exactly 0 arguments (1 given) func_a(**a) #正常输出 def func_b(*args, **kwargs): print args print kwargs func_b(a) #result ({'key': 'value'},) {} func_b(*a) #result ('key',) {} func_b(**a) #result () {'key': 'value'} func_b(test="hello", **a) #result () {'test':'hello', 'key':'value'}
原文地址:http://blog.csdn.net/xiaowangwindow/article/details/40819111