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 学生节祝福语大全简短