Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!reader01.nrc01.news.zen.net.uk.POSTED!not-for-mail From: Nobody Subject: Re: is operator versus id() function Date: Sat, 06 Apr 2013 14:35:03 +0100 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-Id: Newsgroups: comp.lang.python References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines: 20 Organization: Zen Internet NNTP-Posting-Host: 202cc3a4.news.zen.co.uk X-Trace: DXC=7Y12EG[69kB;dNhMZVkA7Fa0UP_O8AJoL=dR0\ckLKG@WeZ<[7LZNRFIcTDNlmdJC@M2Z^cWRFGAKcWSYGTkn8cL X-Complaints-To: abuse@zen.co.uk Xref: csiph.com comp.lang.python:42910 On Fri, 05 Apr 2013 06:49:14 -0700, Candide Dandide wrote: > So, could someone please explain what exactly the is operator returns ? > The official doc says : > > The ‘is‘ operator compares the identity of two objects; the id() > function returns an integer representing its identity (currently > implemented as its address). The docs are correct. But an identity is only unique for the lifetime of the object, so "x is y" and "id(x)==id(y)" are only equivalent if the lifetimes of x and y overlap. If the objects have disjoint lifetimes (i.e. one is created after the other has been destroyed), then it's possible for id() to return the same value for both objects, so id(x)==id(y) can return a "false positive" result, as happened in your example.