Python *args使用方法:
#!/usr/bin/env python#-*- coding=utf-8 -*-def args(args,*kwargs): print (args) for arg in kwargs: print (arg)if __name__ == "__main__": args('hello',"python","变量","111",111)
运行结果:
[root@bogon code]# python test.py hellopython变量111111
Python **kwargs使用方法:
#!/usr/bin/env python#-*- coding=utf-8 -*-def greet_me(**kwargs): for key,value in kwargs.items(): print key,valueif __name__ == "__main__": my_info={'name':'gsw','email':'slysly759@gmail.com'} greet_me(**my_info) #传字典参数 greet_me(name="gsw",qq='948691540',email="gswcfl2013@sina.cn") #传多键值对参数
运行结果:
[root@bogon code]# python test.py name gswemail slysly759@gmail.comqq 948691540name gswemail gswcfl2013@sina.cn