True inconsistency in Python

Erik Max Francis max at alcyone.com
Thu Nov 13 00:21:03 EST 2003


Scott Chapman wrote:

> Historically Python has allowed <> 0 to equal true in evaluations. 
> Now
> <> 0 still evaluates to true in evaluations. However it doesn't equal
> True.  They are not interchangable.  (Same with empty lists, etc.)

That's because the proper way to test for truth does not use the True
value at all.  It is this:

	if x:
	    ...

not this:

	if x == True:
	    ...

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ Life is a predicament which precedes death.
\__/  Henry James




More information about the Python-list mailing list