[Python-ideas] for/else syntax
Steven D'Aprano
steve at pearwood.info
Fri Oct 2 06:24:05 CEST 2009
On Fri, 2 Oct 2009 01:23:27 pm Robert Kern wrote:
> > for x in xs:
> > if cond(x):
> > process()
> > else:
> > process_differently()
> > else:
> > do_something_else()
> >
> >
> > for x in xs:
> > process()
> > else:
> > do_something_else()
> >
> >
> > They don't look anything like an indentation error to me.
>
> Am I missing something? Since those examples don't have any break
> statements in them, why do you use an else:?
My bad -- process and process_differently are meant to stand in for a
*block*, presumably including a break, not just a function call. I was
attempting to show the indent structure. I shouldn't have included the
parentheses, which just muddied the water.
--
Steven D'Aprano
More information about the Python-ideas
mailing list