作者:LAMP小白 点击:1578 发布日期:2013-10-20 01:25:21 返回列表
多类型传值
%s 代表这个位置是字符串
"%s : %s" % 元组 将元组按顺序赋值到相应位置
在实参前面加上一个*号 就能展开这个实参
在实参前面加上** 即可将字典一一对应传入函数
传值冗余
f(x, *args)
args用于接收多余的实参,并存放在args元组中
**dic
**dic用于接收有影射关系的多余实参
#!/usr/bin/python #coding:utf8 def str(a, b): print "%s--%s" % (a,b) str('aaaa', 'bbb') def str2(a, b, c): print "%s--%d--%s" % (a,b,c) arg=('aaa', 1000, 'bbb') str2(*arg) arg2={'a':'aaa', 'b':1000, 'c':'bbb'} str2(**arg2) def str3(f, *d, **a): print f print d print a arg3={'f':'ok', 'other':'no'} d=(1,2,3,4) str3(**arg3) str3(*d)
上一篇:函数的局部变量和全局变量 下一篇:快递查询API