Seemingly odd 'is' comparison.

Boris Borcic bborcic at gmail.com
Tue Feb 19 16:30:24 CET 2008


Duncan Booth wrote:
> Boris Borcic <bborcic at gmail.com> wrote:
>> Arnaud Delobelle wrote:
>>> Whereas when "3.0*1.0 is 3.0" is evaluated, *two* different float
>>> objects are put on the stack and compared (LOAD_CONST 3 / LOAD_CONST
>>> 1 / COMPARE_OP 8).  Therefore the result is False.
>> Looks good, but doesn't pass the sanity check ;) Consider
>>
>>>>> def f():
>>      return 3 is 3, 3*1 is 3
>>
>>>>> import dis
>>>>> dis.dis(f)
>>    2           0 LOAD_CONST               1 (3)
>>                3 LOAD_CONST               1 (3)
>>                6 COMPARE_OP               8 (is)
>>                9 LOAD_CONST               3 (3)
>>               12 LOAD_CONST               1 (3)
>>               15 COMPARE_OP               8 (is)
>>               18 BUILD_TUPLE              2
>>               21 RETURN_VALUE
>>>>> f()
>> (True, True)
>>
> 
> s/different/possibly different depending on implementation details/

"0 substitutions made", but whatever

s/on implementation details/on further implementations details/

> Arnaud's point remains valid: in the first comparison you can see that the 
> same object is used, in the second case all bets are off.

Sure, but the issue was to explain the strangeness that

(3.0 is 3.0)!=(3.0*1.0 is 3.0)

and I just pointed out - without drawing any conclusion - that a structurally 
identical explanation would "explain" the contrafactual (3 is 3)!=(3*1 is 3).

Best, BB




More information about the Python-list mailing list