[Python-ideas] for/else statements considered harmful

Steven D'Aprano steve at pearwood.info
Fri Jun 8 17:08:33 CEST 2012

Devin Jeanpierre wrote:

> I've never been sure of what is good style here. It's comparable to
> these two things:
> def foo():
>     if bar():
>         return baz
>     return quux
> def foo2():
>     if bar():
>         return baz
>     else:
>         return quux
> Is there some well-accepted rule of which to use?

Not in my opinion. Due to laziness (why write an extra line that isn't 
necessary?), I tend to prefer the first version, but have been known to also 
use the second version on some occasions.


More information about the Python-ideas mailing list