create boolean

Lie Ryan lie.1296 at gmail.com
Sun Mar 8 10:49:17 EDT 2009


Scott David Daniels wrote:
> Lie Ryan wrote:
>> Fencer wrote:
>> The literal translation of that would be:
>> if n is not None and n != []:
>>     b = True
>> else:
>>     b = False
>> it is a bit verbose, so one might want to find something shorter
>> b = True if n is not None and n != [] else False
>> I always feel if and in-line if to be easier and more readable than 
>> short-circuited operations.
> 
> How about:
>    b = None is not n != []
> 
> It is amazing to think about how rarely we consider is / is not as
> a comparison operator.  Also, and more reasonably, we often don't
> consider "chaining" comparisons that are intransitive.

The fact that chaining operator is possible doesn't mean it must be 
used. The only place I would use chained operator is for comparing 
ranges of integer: 5 < x < 10, other than that, its use often reduce 
readability.



More information about the Python-list mailing list