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 官宣新年祝福语简短