Python Basic Doubt

Joshua Landau joshua at landau.ws
Sun Aug 11 00:04:22 EDT 2013


On 11 August 2013 04:43, Chris Angelico <rosuav at gmail.com> wrote:
> On Sun, Aug 11, 2013 at 4:21 AM, Gary Herron
> <gary.herron at islandtraining.com> wrote:
>> On 08/10/2013 06:00 PM, Chris Angelico wrote:
>>> All it takes is a slightly odd or buggy __eq__ implementation and the
>>> == versions will misbehave. To check if an argument is something, you
>>> use "is", not ==.
>>
>> No, sorry, but any use of the word "is" in an English sentence is way too
>> ambiguous to specify a correct translation into code.   To check "if a
>> calculation of some value is a million", you'd write
>>         value == 1000000
>> not
>>         value is 1000000
>> even though there are plenty of other examples where "is" would be correct.
>
> Granted, English is a poor litmus test for code. But in this
> particular example, we're talking about immutable types (simple
> integers), where value and identity are practically the same. A Python
> implementation would be perfectly justified in interning *every*
> integer, in which case the 'is' would work perfectly here. The
> distinction between the two is important when the objects are mutable
> (so they have an identity that's distinct from their current values).

I don't follow this argument. Tuples are immutable yet you're crazy if
you check their equality with "is". In Python identity and equality
are very distinct.

I follow (and agree) with the other arguments: "is" is useful and
should be used. It's just this part in particular sounds off.



More information about the Python-list mailing list