解压赋值 不定长参数
>>> li = [('tar', 1, 2),
('goo', 3),
('tar', 4, 5)]
... ... >>>
li
[('tar', 1, 2), ('goo', 3), ('tar', 4, 5)]
>>> li
[('tar', 1, 2), ('goo', 3), ('tar', 4, 5)]
>>> def do_tar(x, y):
... print('tar', x, y)
...
>>> def do_goo(x):
... print('goo', x)
...
>>> for name, *args in li:
if name == 'tar':
do_tar(*args)
elif name == 'goo':
do_goo(*args)
... ... ... ... ...
tar 1 2
goo 3
tar 4 5
>>> li = ['test', 10, 20, 30, 40, 3, 5, 7, ['happy', 'new', 'year'], ('生', '日', '快' ,'乐')]
>>> x, *number, [hh, *_],(*_, le) = li
>>> x
'test'
>>> number
[10, 20, 30, 40, 3, 5, 7]
>>> hh
'happy'
>>> le
'乐'
>>> def zi_p(x=0, y=0, z=0):
... print(x, y, z)
...
>>> d = {}
>>> d.update(['x1', 'y2', 'z3'])
>>> d
{'x': '1', 'y': '2', 'z': '3'}
>>> zi_p(**d)
1 2 3
>>>
浙公网安备 33010602011771号