Home > Backend Development > Python Tutorial > Summarize some functions in python

Summarize some functions in python

零下一度
Release: 2017-06-25 10:16:53
Original
1545 people have browsed it

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
Copy after login
y默认为20
def foo( x,y=20): ##关键字参数
Copy after login
*z接收一个元组
Copy after login
<em><em><em>  for myz in<strong> z</strong>:<br><em>    print 'z: ', myz</em></em></em></em>
Copy after login
关键字可变长参数(字典):**w接收的是一个字典
Copy after login
def foo(x,y=20,*z,**w):  ##默认参数
Copy after login
  for wArg in w.keys():
        print 'wArg %s: %s' % (wArg, str(w[wArg]))
Copy after login
<br><br><br><br><br><br>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template