Empty string is False right?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Jan 31 07:26:50 EST 2009


En Sat, 31 Jan 2009 10:16:19 -0200, AJ Ostergaard <aj at cubbyhole.net>  
escribió:

> Hi Ralf,
>
> Thanks for that but why:
>
>  >>> '' and True
> ''
>
> Surely that should be False?!?

Python does "short-circuit evaluation" [1]
"and" and "or" return one of its operands as soon as the outcome is  
determined, not just True or False.
'' is a false value, as false as False itself :)
After seeing that, there is no point in evaluating the second operand  
(True) because the final result cannot be true; so Python just returns the  
first operand.

[1] http://en.wikipedia.org/wiki/Short_circuit_evaluation

-- 
Gabriel Genellina




More information about the Python-list mailing list