Python中的return语句
语句return[expression]退出一个函数,可以选择将一个表达式传递回调用方。没有参数的return语句与returnNone相同。
示例
以上所有示例均未返回任何值。您可以从函数返回值,如下所示:
#!/usr/bin/python Function definition is here def sum( arg1, arg2 ): # Add both the parameters and return them." total = arg1 + arg2 print "Inside the function : ", total return total; # Now you can call sum function total = sum( 10, 20 ); print "Outside the function : ", total
输出结果
执行以上代码后,将产生以下结果-
Inside the function : 30 Outside the function : 30
热门推荐
10 生日祝福语祝自己简短
11 疫情对妈妈祝福语简短
12 升大学祝福语简短女生
13 冬至宾馆祝福语简短独特
14 中秋祝福语简短有深度
15 美好的毕业祝福语简短
16 送米的祝福语简短
17 分别祝福语简短情话英文
18 自己生日祝福语段子简短