need clarification on -0

Erik Max Francis max at alcyone.com
Sat Nov 28 08:55:18 CET 2009


moijes12 wrote:
> I know the value -0 is quite meaningless and makes little sense.But I
> was just fiddling.I am unable to figure out the below result
> 
>>>> -0 and True
> 0 ----------> (Why is this 0 and not say True or False)
>>>> -0 and false
> 0
>>>> -0 or True
> True
> 
> Could someone please provide me some resources on how these operations
> take place.I'd wanna find it out myself

Your questions have nothing to do with -0, as it's no different from 0:

 >>> 0 == -0
True

Your examples work the same way with simply 0, which is considered a 
false value:

 >>> bool(0)
False
 >>> 0 and True
0
 >>> 0 and False
0
 >>> 0 or True
True

What you're seeing is simply the short-circuiting behavior of the `and` 
and `or` operators; they return the last (relevant) value they 
encountered before making their determination of the value of the 
overall expressions.  See python.org/doc for more information.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   You'll survive / A true Darwin star
    -- Des'ree



More information about the Python-list mailing list