Python Basic Doubt

Chris Angelico rosuav at gmail.com
Sun Aug 11 00:38:51 EDT 2013


On Sun, Aug 11, 2013 at 5:04 AM, Joshua Landau <joshua at landau.ws> wrote:
> On 11 August 2013 04:43, Chris Angelico <rosuav at gmail.com> wrote:
>> 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.

True, it's not strictly an issue of mutability of that one level. But
anything that's truly immutable (a tuple/frozenset of ints/strings)
can in theory be interned. In some languages (no Pythons as far as I'm
aware, though one could easily do so and still be fully compliant),
all strings are automatically interned, so there's no difference
between value and identity for them. A tuple containing a list, for
instance, needs its identity; a tuple of three integers is
identifiable entirely by its value.

ChrisA



More information about the Python-list mailing list