Puzzled by "is"

Jay Loden jloden at jayloden.com
Thu Aug 9 13:49:30 EDT 2007



Jay Loden wrote:
> Dick Moores wrote:
>>  >>> () is ()
>> True
>>  >>> (1,) is (1,)
>> False
>>
>> Why?
>>
>> Thanks,
>>
>> Dick Moores
> 


>From the docs for 'is':

  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. x is not y yields the inverse
  truth value.



So you're actually testing whether or not the identity of the object is the
same, not whether (1,) == (1,):

>>> (1,) == (1,)
True
>>> id((0,)) == id((0,))
False

-Jay



More information about the Python-list mailing list