what is the keyword "is" for?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Aug 16 04:06:03 EDT 2006


In <slrnee5jl8.sj2.sybrenUSE at schuimige.stuvel.eu>, Sybren Stuvel wrote:

> Dan Bishop enlightened us with:
>>>>> a = b = 1e1000 / 1e1000
>>>>> a is b
>> True
>>>>> a == b
>> False
> 
> If "a is b" then they refer to the same object, hence a == b. It
> cannot be otherwise, unless Python starts to defy logic. I copied your
> code and got the expected result:
> 
>>>> a = b = 1e1000 / 1e1000
>>>> a is b
> True
>>>> a == b
> True

I get the same as Dan:

In [13]: a = b = 1e1000 / 1e1000

In [14]: a is b
Out[14]: True

In [15]: a == b
Out[15]: False

In [16]: a
Out[16]: nan

On my platform the division results in "Not A Number".  Two NaNs compared
are always `False`.  You could argue that this is the very same NaN but to
get this effect the interpreter has to take care that every NaN produced
while a program is running is unique.  Quite huge overhead for such a
corner case IMHO.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list