Implicit conversion to boolean in if and while statements

Steven D'Aprano steve+comp.lang.python at
Tue Jul 17 03:12:47 CEST 2012

On Mon, 16 Jul 2012 13:28:14 -0400, Dennis Lee Bieber wrote:

> On 16 Jul 2012 02:38:35 GMT, Steven D'Aprano
> <steve+comp.lang.python at> declaimed the following in
> gmane.comp.python.general:
>> On Sun, 15 Jul 2012 12:02:37 -0500, Andrew Berg wrote:
>> > Okay, I see the value in this, but I don't understand why None has a
>> > truth value.
>> And this is exactly the sort of mental confusion that Laura Crichton
>> warned about (see the link I included earlier).
> 	Would one rather have the behavior seen in SQL for Null?

That's a 51 page document. I'm not sure I know which behaviour you are 
referring to.

Seems to me that the Firebird NULL object is closer to a float NaN than 
to Python's None, except that Firebird treats comparisons with NULL as 
returning a NULL, while Python treats comparisons with NaN as True or 

Both behaviours are reasonable, but the Firebird behaviour seems to be 
more error-prone.

> 	Hey, let's turn the IF statement into tri-state logic...

I'm not sure if you're being sarcastic here or not. Ternary logic is 
perfectly reasonable, although I expect that it would be error-prone 
because programmers would forget the "unknown" clause all the time. It 
looks like Firebird implements the variety of ternary logical called 
"Keene logic".

Of course, ternary logic can always be re-written in binary terms. 
Assuming that UNKNOWN evaluates as false:

if flag:
    if flag is UNKNOWN:


More information about the Python-list mailing list