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
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短