[Tutor] c++::return

elis aeris hunter92383 at gmail.com
Wed Mar 19 04:45:40 CET 2008


I actually said "ending" to avoid problems with different terminology
between different languages - but i guess a return is still a return in
python.

i did this search

http://www.google.ca/search?hl=en&q=python+tutorial+return&btnG=Google+Search&meta=

and it didn't return any particularly obvious answer.

The funny thing is, i wrote that program last june and managed to not
know/use a single return :)







On Tue, Mar 18, 2008 at 6:11 PM, Alan Gauld <alan.gauld at btinternet.com>
wrote:

> "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
> >>int main(){}
> >>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
> function. ...
>      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
> substituted.
>
> 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.
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080318/95f946a4/attachment.htm 


More information about the Tutor mailing list