Short-circuit Logic

Cameron Simpson cs at zip.com.au
Mon May 27 02:13:20 EDT 2013


On 27May2013 06:59, Vito De Tullio <vito.detullio at gmail.com> wrote:
| Cameron Simpson wrote:
| >   if s is not None and len(s) > 0:
| >     ... do something with the non-empty string `s` ...
| > 
| > In this example, None is a sentinel value for "no valid string" and
| > calling "len(s)" would raise an exception because None doesn't have
| > a length.
| 
| obviously in this case an `if s: ...` is more than sufficient :P

:P

My fault for picking too similar a test.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

Death is life's way of telling you you've been fired.   - R. Geis



More information about the Python-list mailing list