Function parameters in python include: default parameters, keyword parameters, non-keyword variable-length parameters (tuple), keyword variable-length parameters (dictionary)
:在函数声明时,指定形参的默认值,调用时可不传入改参数(使用默认值) def foo(x): ##默认参数 print 'x is %s' % x
y默认为20 def foo( x,y=20): ##关键字参数
*z接收一个元组
<em><em><em> for myz in<strong> z</strong>:<br><em> print 'z: ', myz</em></em></em></em>
关键字可变长参数(字典):**w接收的是一个字典
def foo(x,y=20,*z,**w): ##默认参数
for wArg in w.keys(): print 'wArg %s: %s' % (wArg, str(w[wArg]))
<br><br><br><br><br><br>
The above is the detailed content of Summarize some functions in python. For more information, please follow other related articles on the PHP Chinese website!