北京治疗白癜风最好的医生 http://pf.39.net/bdfyy/
引领前沿
Python
NewAccounting
会计如艺术,
代码如诗词。
#1
本期主题
Currenttheme
函数及其参数
Functionsandarguments
函数
Functions
函数参数
FunctionArguments
关键字参数
KeywordArguments
返回值
ReturningValue
递归函数
Recursivefunction
#2
内容
content
01
函数Functions
1.1什么是函数
Whatisfunction?
函数是实现特定功能的代码段,可以通过函数名来调用这段代码。函数需要具备参数,返回值和内部实现过程三个元素。
Afunctionisapieceofcodethatimplementsaspecificpurposeandcanbenamedbytheofthecorrespondingfunctionname.Afunctionconsistsofthreeelements:anargument,areturningvalue,andaninternalimplementation.
分类:
内建函数:
max()、min()、sum()等
库函数:
math.pow(x,y)x的y次方
自定义函数:
使用def()自定义
Classification:
Built-infunction:
suchasmax(),min(),sum(),etc.
Libraryfunction:
math.pow(x,y)theythpowerofx
Self-definingfunction:
self-defineafunctionbydef()
def
Python函数是使用def关键字定义的,后跟函数名。函数名后面是一组匹配的圆括号,用于括起函数的任何参数。冒号字符紧跟在右括号之后,表示提供函数实现的代码块的开始,该代码块称为函数体。
APythonfunctionisdefinedbythedefkeyword,followedbythefunctionname.Thefunctionnameisfollowedbyamatchingsetofbracketsthatencloseanyargumentstothefunction.Thereafter,acoloncharactershallfollowtheclosingbracket,representingthebeginningoftheblockofcodethatprovidesthefunctionsimplementation.Theblockiscalledthefunctionbody.
格式:
def函数名(参数列表):
函数体:
有零到多条可执行性语句组成的函数
Format:
deffunctionname(argumentlist)
Functionbody:
Thefunctionconsistsofzerooranumberofexecutablestatements.
[Optional:returnfunctionvalue]
1In[1]:#Example:2In[2]:defhello(name):#name是参数列表,不过只有一个3...:"""Displayawel