is implemented with id ?

Aahz aahz at
Sun Nov 4 06:12:10 CET 2012

Hans Mulder  <hansmu at> wrote:
>On 3/11/12 20:41:28, Aahz wrote:
>> In article <50475822$0$6867$e4fe514c at>,
>> Hans Mulder  <hansmu at> wrote:
>>> On 5/09/12 15:19:47, Franck Ditter wrote:
>>>> - I should have said that I work with Python 3. Does that matter ?
>>>> - May I reformulate the queston : "a is b" and "id(a) == id(b)"
>>>>   both mean : "a et b share the same physical address". Is that True ?
>>> Yes.
>>> Keep in mind, though, that in some implementation (e.g.  Jython), the
>>> physical address may change during the life time of an object.
>>> It's usually phrased as "a and b are the same object".  If the object
>>> is mutable, then changing a will also change b.  If a and b aren't
>>> mutable, then it doesn't really matter whether they share a physical
>>> address.
>> That last sentence is not quite true.  intern() is used to ensure that
>> strings share a physical address to save memory.
>savings are minor; the time savings may be significant.

As others have pointed out, using ``is`` with strings is a Bad Habit
likely leading to nasty, hard-to-find bugs.

intern() costs time, but saves considerable space in any application
with lots of duplicate computed strings (hundreds of megabytes in some
Aahz (aahz at           <*>


More information about the Python-list mailing list