[Tutor] returning from 2 functions at once

Alan Gauld learn2program at gmail.com
Fri Oct 8 19:44:10 EDT 2021


On 08/10/2021 20:37, Ed Connell wrote:
> Hello,
>
> Is there a way to return from a function because of the return of a
> subfunction.  Don't know if I said that right, so I'll give an example.
>
> Say you have function f1 and f2,
>
> def f1( *args )

The example got lost. But if I understand you correctly the answer is
no, not easily.
Or maybe yes, that's the default....

That's because when you call a function from inside another function the
outer
function stops executing and waits for the inner function to complete.
So when
the inner function returns you have the option of exiting the outer
function
if you want. Or you can test the return value and only exit under certain
conditions, or you can just ignore the inner function's return and continue
with the outer function. It's up to you.

But the important point is that the outer function stops while the inner
executes.
You can get round that with threading and concurrency but that's a way
more complex scenario.

If that's not what you meant you need to repost with a more complete
example.

-- 

Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list