Jack Diederich <[EMAIL PROTECTED]> wrote:

> I can't say I use it for much else, if I really want a default I do
> found = None
> for (thing) in searchlist:
>   if (matches(thing)):
>     found = None
>     break
> 
> That could end with 'else: found = None' to assign a default but I
> like the default to come first for readability.

Actually I think assigning the fall-back value in an "else" branch is
more readable. To some extent it's just a feeling, but there's two
things: For one, it gives you all assignments to the result at closer,
if not the same, indentation levels. More importantly, the value is
unconditionally set by a single statement, namely the "for" construct,
instead of by either the first or both, the second assignment basically
making the first superfluous. Using "else" models better what you want
to do, IMO.

-- 

Viele Grüße,
Thomas
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to