1. 函数的可变参数:
*args and **kwargs——This is a Python feature that allows a function to accept a dynamic, arbitrarynumber of arguments whose names aren’t known until runtime.
*把位置参数们转为一个tuple:
(If you put a singleasterisk in front of a parameter in a function definition, any positional arguments to that function will be rolled up into a single tuple. )
**把关键字参数们转为一个dictionary:
If you puttwo asterisks in front of a parameter in a function definition, any keyword arguments to that function will be rolled up into a single dictionary.
比如:
>>> foo(1, 2, 3)
Positional arguments are:
(1, 2, 3)
Keyword arguments are:
{}
>>> foo(1, 2, name='Adrian', framework='Django')
Positional arguments are:
(1, 2)
Keyword arguments are:
{'framework': 'Django', 'name': 'Adrian'}
转载于:https://blog.51cto.com/halolk/1251950