If/then style question
Mark Wooding
mdw at distorted.org.uk
Fri Dec 17 11:45:01 EST 2010
Steve Holden <steve at holdenweb.com> writes:
> I think the choice of keyword is probably not Guido's crowning
> language achievement,
I remember the behaviour by considering a typical application:
for thing in things:
if shinyp(thing):
break
else:
raise DullError, 'nothing shiny found'
In this kind of search loop, `break' signifies a kind of successful
completion: the `for' loop can be considered to be a test acting over an
iterable, and `else' therefore denotes the action if the test fails.
I don't know whether that's the official intuition, or even if there is
an official intuition, but it works well enough for me. I'm quite fond
of Python's extra `else' clauses in `for' and (particularly) `try'.
-- [mdw]
More information about the Python-list
mailing list