alan.gauld at btinternet.com
Wed Mar 19 02:11:59 CET 2008
"elis aeris" <hunter92383 at gmail.com> wrote
> how do I return a function?
Do you realise that this is an entirely different question
to the one you asked originally, namely:
>> what do I do if i want the program/function to end?
>> in c++ of
>>I do a return 0;
One is asking about *ending* the program(or function), the
other about returning. Those are two different concepts.
In particular returning implies that the program does not
end but goes on to use the returnedvalue in some way.
Assuming that it is returning you are interested in then
all the tutorials that discuss Python functions (including
mine) will tell you how to return a value from a function.
You use the return statement exactly like in C++.
Where did you look if you couldn't find it?
Even searching "return" on the Python web site gets me this as
the first link:
6.7 The return statement
When return passes control out of a try statement with a finally
clause, that finally clause is executed before really leaving the
docs.python.org/ref/return.html - 7k - Cached - Similar pages
And visiting it it tells me:
-----------------------return_stmt ::= "return" [expression_list]
return may only occur syntactically nested in a function definition,
not within a nested class definition.
If an expression list is present, it is evaluated, else None is
return leaves the current function call with the expression list (or
None) as return value.
Now, its not that we mind answering questions, but if you claim
to have looked for an answer and then ask a somewhat vaguely
worded question we will assume you are looking for something
deeper. Its easier for all of us if you are as specific as possible
in your questions.
Author of the Learn to Program web site
More information about the Tutor