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 妈妈生日祝福语简短励志