Skip to content

Commit 2bdc441

Browse files
committed
feat: Unpacking tuples and dictionaries
1 parent cb9291a commit 2bdc441

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def demo(*args, **kwargs):
2+
3+
print(args)
4+
print(kwargs)
5+
6+
7+
# 元组/字典变量
8+
gl_num = (1, 2, 3)
9+
gl_dict = {"name":"小明", "age":18}
10+
11+
# 会将两个参数都传递给 *args
12+
demo(gl_num, gl_dict)
13+
14+
# 拆包语法,简化元组/自带你变量的传递
15+
demo(*gl_num, **gl_dict)
16+
17+
# 等价于
18+
demo(1, 2, 3, name="小明", age=18)

0 commit comments

Comments
 (0)