近期有很多小伙伴咨询小编python怎么定义函数,接下来就让我们一起学习一下python定义函数的方法吧,希望可以帮助到大家。
python怎么定义函数?python定义函数的方法
1、通过def来进行函数定义,本次定义一个num_sum()函数,并传入参数为num1和num2(如下图所示)。

2、在定义函数的下方,使用连续的一对三引号,在一对三引号之间编写对函数的说明文字(如下图所示)。

3、用result = num1 + num2来编写函数内部的代码(如下图所示)。

4、利用关键字return来返回想要返回的值,返回result,就可以看到函数定义完成(如下图所示)。

上面就是小编为大家带来的python怎么定义函数的全部内容,更多精彩教程尽在华军下载。