版权声明:本文为CSDN博主「Nicolas Léon Deng」的原创文章 原文链接:https://blog.csdn.net/Arctic_Beacon/article/details/88185360
def print_params_1(params):
print params
def print_params_2(*params):
print params
def print_params_3(**params):
print params
上述3个函数参数,分别传递单参数、tuple、dictionary。
print_params_1('123')
print_params_1(1.0)
print_params_1('123',1)
输出
123
1.0
Traceback (most recent call last):
File "<ipython-input-34-04a2747a3396>", line 16, in <module>
print_params_1('123',1)
TypeError: print_params_1() takes exactly 1 argument (2 given)
print_params_2(1, 2, 3)
print_params_2(1.0)
print_params_2('x')
输出
(1, 2, 3)
(1.0,)
('x',)
print_params_3(x=1, y=2, z=3)
print_params_3(x=1)
print_params_3(1,2,3)
输出
{'y': 2, 'x': 1, 'z': 3}
{'x': 1}
Traceback (most recent call last):
File "<ipython-input-49-8e76288e4dcb>", line 3, in <module>
print_params_3(1,2,3)
TypeError: print_params_3() takes exactly 0 arguments (3 given)