Skip to content

Commit 4782217

Browse files
author
tuntun
committed
使用解析tupple或dict传参的技巧
1 parent 8288114 commit 4782217

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

args_unpacking.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# 使用tupple或dict传参的技巧
4+
5+
def product(a, b):
6+
print(str(a) + '*' + str(b))
7+
return a * b
8+
9+
argument_tuple = (1, 1)
10+
argument_dict = {'a': 1, 'b': 1}
11+
12+
print(product(*argument_tuple)) # 这里用*解析tupple类型的变量作为product的参数
13+
print(product(**{'b':4,'a':3})) # 这里用**解析dict类型的变量作为product的参数

0 commit comments

Comments
 (0)