True inconsistency in Python

Dang Griffith noemail at noemail4u.com
Thu Nov 13 13:33:28 CET 2003


On Wed, 12 Nov 2003 21:21:03 -0800, Erik Max Francis <max at alcyone.com>
wrote:

>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:
>	    ...
Sort of like (stretchy) saying that if these are both True:
   "a snake is green"
   "a pearl is white"
that they are the same as each other.  
They are both true, yet unrelated.  You can say:
   if "a snake is green": print 1
   if "a pearl is white": print 2
and the prints would happen, but if you said
   if "a snake is green" == "a pearl is white": print 3
the print would not happen.

   --dang




More information about the Python-list mailing list