Skip to content

Commit fe7a730

Browse files
author
tuntun
committed
Python3可变参数示例
1 parent 0c53fdb commit fe7a730

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

args_kwargs.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
# encoding:utf-8
2+
3+
# -*- Python3可变参数 -*-
4+
5+
import webbrowser
6+
17
def alias(*args, **kwargs):
28
print('args=', args)
39
print('kwargs=', kwargs)
410

511
alias(3, 23, 3, 3,a='hello',b=3,c='C')
612

7-
'''输出
13+
"""
14+
输出:
815
args= (3, 23, 3, 3)
916
kwargs= {'b': 3, 'c': 'C', 'a': 'hello'}
10-
'''
17+
18+
小结:
19+
*args表示任何多个无名参数,它是一个tuple
20+
**kwargs表示关键字参数,它是一个dict
21+
"""
22+
23+
# 具体参考资料
24+
webbrowser.open('http://www.tantengvip.com/2015/07/python-args-kwargs/', 1)

0 commit comments

Comments
 (0)