一.函数参数和返回值

--参数:负责给函数传递一些必要的数据或者信息

    -形参(形式参数):在函数定义的时候用到的参数,没有具体值,只是一个占位符号

    -实参(实际参数):在调用函数的时候输入的值

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

    example:

>>> def hello(person):
...     print("{0},how are you ?".format(person))
...     print("{},i am fine".format(person))
...
>>> p="claire"
>>> hello(p)     #用P 代替了person,claire 又赋值给P
claire,how are you ?
claire,i am fine
>>>

--返回值:调用函数时候的一个执行结果

  - 使用return返回结果

  - 如果没有值需要返回,我们推荐使用return none 表示函数结束

  -函数一旦执行return,则函数立即结束

  -如果函数没有return关键字,则函数默认返回none。

example:

>>> hh=hello("gigi")
gigi,how are you ?
gigi,i am fine
>>> print(hh)
None
>>>

  

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄