python的* 、**拆包(打散)功能

注:python3 

*示例

>>> a = (1,2,3)
>>> print(a)
(1, 2, 3)
>>> print(*a)
1 2 3
>>> 
>>> b = [1,2,3]
>>> print(b)
[1, 2, 3]
>>> print(*b)
1 2 3
>>> 
>>> c = "123"
>>> print(c)
123
>>> print(*c)
1 2 3
>>> 
>>> d = {"a":1, "b":2, "c":3}
>>> print(*d)

 

**示例

>>> def func_dic(name, age):
...     print(name, age)
... 
>>> func_dic(*dic)
name age
>>> func_dic(**dic)
张三 20

 

posted @ 2021-12-13 09:40  jihite  阅读(239)  评论(0编辑  收藏  举报