6.7 return语句 The return statement

return_stmt  ::=  "return" [expression_list]
Download entire grammar as text.

return may only occur syntactically nested in a function definition, not within a nested class definition.

return在句法上仅可以出现在嵌套的函数定义中, 不能出现在嵌套的类定义中.

If an expression list is present, it is evaluated, else None is substituted.

如果给出了表达式表, 就计算其值, 否则就代以None.

return leaves the current function call with the expression list (or None) as return value.

return的作用是离开当前函数调用, 并以表达式表的值(或None)为返回值.

When return passes control out of a try statement with a finally clause, that finally clause is executed before really leaving the function.

当return放在具有finally子句的try语句中, finally子句中的语句会在函数真正退出之前执行一次.

In a generator function, the return statement is not allowed to include an expression_list. In that context, a bare return indicates that the generator is done and will cause StopIteration to be raised.

在生成器函数中, return语句不允许包括expression_list. 在该种情况下, 空的return语句指出生成器结束,并引发一个StopIteration异常.