[Tutor] multiple function returns

Wayne Werner wayne at waynewerner.com
Fri Jun 28 20:25:23 CEST 2013


On Fri, 28 Jun 2013, Steven D'Aprano wrote:

> On 28/06/13 14:18, Jim Mooney wrote:
>> What's the Pythonic standard on multiple returns from a function? It
>> seems easiest to just return from the point where the function fails
>> or succeeds, even it that's multiple points. Or is it considered best
>> to defer everything to one return at the end?
>
>
> The first. Python functions have one entry point, the top of the function. 
> They can have multiple exit points, anywhere you have a return statement.

If you consider exceptions to be a function return, then every line has at 
*least* one return point ;)


-Wayne


More information about the Tutor mailing list