Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > by-pkgid > 0b7eb7009605a11593fbe388d7fbee61 > files > 1035

python-docs-2.2-9.1mdk.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.7 The return statement </title>
<META NAME="description" CONTENT="6.7 The return statement ">
<META NAME="keywords" CONTENT="ref">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=">
<link rel="STYLESHEET" href="ref.css">
<link rel="first" href="ref.html">
<link rel="contents" href="contents.html" title="Contents">
<link rel="index" href="genindex.html" title="Index">
<LINK REL="next" href="yield.html">
<LINK REL="previous" href="print.html">
<LINK REL="up" href="simple.html">
<LINK REL="next" href="yield.html">
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="print.html"><img src="../icons/previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="simple.html"><img src="../icons/up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="yield.html"><img src="../icons/next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Reference Manual</td>
<td><A href="contents.html"><img src="../icons/contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><A href="genindex.html"><img src="../icons/index.gif"
  border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="print.html">6.6 The print statement</A>
<b class="navlabel">Up:</b> <a class="sectref" href="simple.html">6. Simple statements</A>
<b class="navlabel">Next:</b> <a class="sectref" href="yield.html">6.8 The yield statement</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION008700000000000000000">&nbsp;</A>
<BR>
6.7 The <tt class="keyword">return</tt> statement 
</H1>
<a name="l2h-334">&nbsp;</a>
<P>
<dl><dd class="grammar">
<div class="productions">
<table cellpadding="2">
<tr valign="baseline">
    <td><code><a name="tok-return_stmt">return_stmt</a></code></td>
    <td>&nbsp;::=&nbsp;</td>
    <td><code>"return" [<a href="exprlists.html#tok-expression_list">expression_list</a>]</code></td></tr>
</table>
</div>
<a class="grammar-footer"
  href="grammar.txt" type="text/plain"
  >Download entire grammar as text.</a>
</dd></dl>

<P>
<tt class="keyword">return</tt> may only occur syntactically nested in a function
definition, not within a nested class definition.
<a name="l2h-335">&nbsp;</a>
<P>
If an expression list is present, it is evaluated, else <code>None</code>
is substituted.

<P>
<tt class="keyword">return</tt> leaves the current function call with the expression
list (or <code>None</code>) as return value.

<P>
When <tt class="keyword">return</tt> passes control out of a <tt class="keyword">try</tt> statement
with a <tt class="keyword">finally</tt> clause, that <tt class="keyword">finally</tt> clause is executed
before really leaving the function.
<a name="l2h-336">&nbsp;</a>
<P>
In a generator function, the <tt class="keyword">return</tt> statement is not allowed
to include an <a href="exprlists.html#tok-expression_list">expression_list</a>.  In that context, a bare
<tt class="keyword">return</tt> indicates that the generator is done and will cause
<tt class="exception">StopIteration</tt> to be raised.

<P>

<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="print.html"><img src="../icons/previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="simple.html"><img src="../icons/up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="yield.html"><img src="../icons/next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Reference Manual</td>
<td><A href="contents.html"><img src="../icons/contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><A href="genindex.html"><img src="../icons/index.gif"
  border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="print.html">6.6 The print statement</A>
<b class="navlabel">Up:</b> <a class="sectref" href="simple.html">6. Simple statements</A>
<b class="navlabel">Next:</b> <a class="sectref" href="yield.html">6.8 The yield statement</A>
<hr>
<span class="release-info">Release 2.2, documentation updated on December 21, 2001.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>