Home  >  Article  >  Backend Development  >  Summarize some functions in python

Summarize some functions in python

零下一度
零下一度Original
2017-06-25 10:16:531500browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Python enumeration EnumNext article:Python enumeration Enum