Short-circuit Logic

Vito De Tullio vito.detullio at gmail.com
Mon May 27 00:59:13 EDT 2013


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

-- 
ZeD




More information about the Python-list mailing list