运行系统:win7企业版 64位,Python 3.6.5
第一部分
>>> def print_params(**par):
... print (par)...
>>> printp(1,2,4,5,6,7,'8af','ewr','f',foo=1,bar=2,abc='sdf')
1 2 4
(5, 6, 7, '8af', 'ewr', 'f')
{'foo': 1, 'bar': 2, 'abc': 'sdf'}
第二部分
>>> def add(x,y):return x+y
...
>>> params=(1,2)
>>> add(params)
Traceback (most recent call last):
File "
TypeError: add() missing 1 required positional argument: 'y'
>>> add(*params)
3
字典同理
第三部分
def story(**kwds):
return 'Once upon a time,there was a %(job)s called %(name)s.' % kwds
def power(x,y,*others):
if others:
print('Received redunandt parameters;',others)
return pow(x,y)
def interval(start,stop=None,step=1):
'Imitates range() for step>0'
if stop is None:
start,stop=0,start
result=[]
i = start
while i
i+=step
return result