[Tutor] Discrepancy

Bob Gailer bgailer at alum.rpi.edu
Mon Mar 22 10:27:03 EST 2004


At 06:46 AM 3/19/2004, kiran at mhowlinux.org wrote:
>hi
>
>what is the problem
>
> > x =1
> >x   is   1
>1
> >
> > (1 is 1)
>1
> >
> >x is (1 is 1)
>0
>
>once i set x=1
>x is 1   returns true(1)
>(1 is 1) returns true(1)
>
>whereas
>  x is (1 is 1)
>returns 0

LangaugeReference: "The operators is and is not test for object identity: x 
is y is true if and only if x and y are the same object." Object identity 
is tested by comparing the ids of the 2 objects.
 >>> x = 1
 >>> id(x)
3112784
 >>> id(1 is 1)
504014296 # hmm - what's going on here? Wait a minute didn't it say " y is 
true"
 >>> id(True)
504014296 # Oh now I see. True and 1 are not the same object even though 
they have the same value

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040322/416f6873/attachment.html


More information about the Tutor mailing list