第11章 函数和函数式编程(3)

本文详细介绍了在Python函数调用中如何使用*和**符号指定元组和字典的元素作为非关键字及关键字参数,通过实例展示了非关键字可变长参数的使用方法。

11.6 可变长度的参数

在函数调用中使用*和**符号来指定元组和字典的元素作为非关键字以及关键字参数的方法。

11.6.1 非关键字可变长参数(元组)

可变长的参数元组必须在位置和默认参数之后。

>>> def tupleVarArgs(arg1, arg2 = 'defaultB', *theRest):
... print "Normal arg: ", arg1
... print "Default arg: ", arg2
... for arg in theRest:
... print 'Tuple arg: ', arg
...
>>> tupleVarArgs(11,22,33,44,5,6,7,8,8,100)
 Normal arg:  11
Default arg:  22
Tuple arg:  33
Tuple arg:  44
Tuple arg:  5
Tuple arg:  6
Tuple arg:  7
Tuple arg:  8
Tuple arg:  8
Tuple arg:  100
>>> 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值