for -- else: what was the motivation?

Chris Angelico rosuav at gmail.com
Sun Oct 9 00:47:50 EDT 2022


On Sun, 9 Oct 2022 at 15:39, Axy via Python-list <python-list at python.org> wrote:
>
> Got it, thanks!
>
> Actually the reason I never used "else" was the violation of the rule of
> beauty "shortest block first". With if--else you can easily follow this
> rule by inverting "if" expression, but with for--else you can't. The
> loop body of the simplest example is already three lines, in real life
> things are much worse.
>

That's not a rule I've ever been taught; how important is it?

ChrisA


More information about the Python-list mailing list