python 变量解压赋值
* 数组
** 字典
如
>>> record = [
('bar',1,2),
('foo','hello'),
('bar', 3, 4),
]
>>> def do_bar(x,y):
print('bar',x,y)
>>> def do_foo(s):
print('foo',s)
>>> for name,*args in record:
if name == 'bar':
do_bar(*args) # 解压赋值
elif name == 'foo':
do_foo(*args)
bar 1 2
foo hello
bar 3 4
字典:
>>> def test(a=1,b=2,c=3):
print(a,b,c)
- >>> d = dict(a=4,b=5,c=6)
- >>> test(**d)
重要参考:https://blog.csdn.net/zvall/article/details/79052576
本文来自博客园,作者:BioinformaticsMaster,转载请注明原文链接:https://www.cnblogs.com/koujiaodahan/p/9043856.html
posted on 2018-05-16 00:10 BioinformaticsMaster 阅读(204) 评论(0) 收藏 举报
浙公网安备 33010602011771号