标签:可变 cin alt key cells line width padding value
这是Python函数可变参数 args及kwargs
*args表示任何多个无名参数,它是一个tuple
**kwargs表示关键字参数,它是一个dict
测试代码如下:
1
2
3
4
5
6
7
8
9
|
def foo( * args, * * kwargs): print ‘args=‘ ,args print ‘kwargs=‘ ,kwargs print ‘**********************‘ if __name__ = = ‘__main__‘ : foo( 1 , 2 , 3 ) foo(a = 1 ,b = 2 ,c = 3 ) foo( 1 , 2 , 3 ,a = 1 ,b = 2 ,c = 3 ) foo( 1 , ‘b‘ , ‘c‘ ,a = 1 ,b = ‘b‘ ,c = ‘c‘ ) |
执行结果如下:
1
2
3
4
5
6
7
8
9
10
11
12
|
args = ( 1 , 2 , 3 ) kwargs = {} * * * * * * * * * * * * * * * * * * * * * * args = () kwargs = { ‘a‘ : 1 , ‘c‘ : 3 , ‘b‘ : 2 } * * * * * * * * * * * * * * * * * * * * * * args = ( 1 , 2 , 3 ) kwargs = { ‘a‘ : 1 , ‘c‘ : 3 , ‘b‘ : 2 } * * * * * * * * * * * * * * * * * * * * * * args = ( 1 , ‘b‘ , ‘c‘ ) kwargs = { ‘a‘ : 1 , ‘c‘ : ‘c‘ , ‘b‘ : ‘b‘ } * * * * * * * * * * * * * * * * * * * * * * |
标签:可变 cin alt key cells line width padding value
原文地址:http://www.cnblogs.com/byteHuang/p/6938548.html