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


Groups > comp.lang.python > #42823

is operator versus id() function

X-Received by 10.224.172.200 with SMTP id m8mr5481238qaz.0.1365169754715; Fri, 05 Apr 2013 06:49:14 -0700 (PDT)
X-Received by 10.49.60.170 with SMTP id i10mr924291qer.41.1365169754646; Fri, 05 Apr 2013 06:49:14 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!ca1no30532385qab.0!news-out.google.com!ef9ni1849qab.0!nntp.google.com!ca1no30532384qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Fri, 5 Apr 2013 06:49:14 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=82.245.68.143; posting-account=J_U-0woAAACrUCMCI_QdLAKny8A2zeDX
NNTP-Posting-Host 82.245.68.143
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <ed17e4ac-2000-42ef-aa2b-69ff421ae3fa@googlegroups.com> (permalink)
Subject is operator versus id() function
From Candide Dandide <c.candide@laposte.net>
Injection-Date Fri, 05 Apr 2013 13:49:14 +0000
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.python:42823

Show key headers only | View raw


Until now, I was quite sure that the is operator acts the same as the id builtin function, or, to be more formal, that o1 is o2 to be exactly equivalent to id(o1) == id(o2). This equivalence is reported in many books, for instance Martelli's Python in a Nutshell.

But with the following code, I'm not still sure the equivalence above is correct. Here's the code :


#--------------------------------------------------------
class A(object):
    def f(self):
        print "A"

a=A()
print id(A.f) == id(a.f), A.f is a.f
#--------------------------------------------------------


outputing:

True False

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).

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


Thread

is operator versus id() function Candide Dandide <c.candide@laposte.net> - 2013-04-05 06:49 -0700
  Re: is operator versus id() function Arnaud Delobelle <arnodel@gmail.com> - 2013-04-05 15:53 +0100
    Re: is operator versus id() function candide <c.candide@laposte.net> - 2013-04-05 09:40 -0700
      Re: is operator versus id() function Tim Delaney <timothy.c.delaney@gmail.com> - 2013-04-06 06:57 +1100
    Re: is operator versus id() function candide <c.candide@laposte.net> - 2013-04-05 09:40 -0700
  Re: is operator versus id() function Nobody <nobody@nowhere.com> - 2013-04-06 14:35 +0100

csiph-web