#定义一个含有不定长参数的函数,本例第三个参数*args
def sum_nums(a,b,*args):
print(‘_‘*30)
print(a)
print(b)
print(args)
#调用函数:
sum_nums(11,22,33,44,55,66,77)
sum_nums(11,22,33)
sum_nums(11,22)
sum_nums(11)#错误调用,传递的参数不够
#输出结果:
______________________________
11
22
(33, 44, 55, 66, 77)
______________________________
11
22
(33,)
______________________________
11
22
()
Traceback (most recent call last):
File "6.py", line 10, in <module>
sum_nums(11)#错误调用
TypeError: sum_nums() missing 1 required positional argument: ‘b‘
原文地址:https://www.cnblogs.com/littlesuns/p/9955068.html
时间: 2024-10-12 01:00:04