Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52356

Re: Python Basic Doubt

References (4 earlier) <CAPTjJmoM=MU2eqa2i_5_RbveXMqScQqu_uFjonwdrZX7Vsc49g@mail.gmail.com> <5206DDED.8030506@islandtraining.com> <CAPTjJmrUGWnQ40iPiJtdKAB8WTbjRaM+bzUmukY6Cb4FvOi2JQ@mail.gmail.com> <5207034A.6070608@islandtraining.com> <CAPTjJmoj5K838vfjuEx9HGDuSb_Uq3=OckqksEk0YsM5Qb4P2w@mail.gmail.com>
From Joshua Landau <joshua@landau.ws>
Date 2013-08-11 05:04 +0100
Subject Re: Python Basic Doubt
Newsgroups comp.lang.python
Message-ID <mailman.463.1376193904.1251.python-list@python.org> (permalink)

Show all headers | View raw


On 11 August 2013 04:43, Chris Angelico <rosuav@gmail.com> wrote:
> On Sun, Aug 11, 2013 at 4:21 AM, Gary Herron
> <gary.herron@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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python Basic Doubt Joshua Landau <joshua@landau.ws> - 2013-08-11 05:04 +0100

csiph-web