why () is () and [] is [] work in other way?
Bernd Nawothnig
Bernd.Nawothnig at t-online.de
Mon Apr 23 16:43:53 EDT 2012
On 2012-04-23, Paul Rubin wrote:
> Kiuhnm <kiuhnm03.4t.yahoo.it> writes:
>> I can't think of a single case where 'is' is ill-defined.
>
> If I can't predict the output of
>
> print (20+30 is 30+20) # check whether addition is commutative
> print (20*30 is 30*20) # check whether multiplication is commutative
>
> by just reading the language definition and the code, I'd have to say
> "is" is ill-defined.
"is" was never designed for comparing literals or expressions.
the expression
20+30 is 30+20
maybe syntactically correct but is nevertheless pretty senseless and
you can, of course, not check commutativity with it.
For checking commutativity you have to use:
20+30 == 30+20
>
>> You're blaming 'is' for revealing what's really going on. 'is' is
>> /not/ implementation-dependent. It's /what's going on/ that's
>> implementation-dependent.
>> "a is b" is true iff 'a' and 'b' are the same object. Why should 'is'
>> lie to the user?
>
> Whether a and b are the same object is implementation-dependent.
>>> a = something
>>> b = a
>>> a is b
True
Should be guaranteed and implementation-independent.
Bernd
--
"Die Antisemiten vergeben es den Juden nicht, dass die Juden Geist
haben - und Geld." [Friedrich Nietzsche]
More information about the Python-list
mailing list