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


Groups > comp.lang.python > #86140

Re: id() and is operator

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <lac@openend.se>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.018
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'laura': 0.07; 'suppose': 0.07; 'wrong,': 0.09; '--------': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'numpy': 0.16; 'received:openend.se': 0.16; 'received:theraft.openend.se': 0.16; 'skip:> 20': 0.16; 'so.': 0.16; 'feb': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**1': 0.23; 'lets': 0.24; 'question': 0.24; 'header:In-Reply- To:1': 0.27; 'correct': 0.29; 'dec': 0.30; '>>>>': 0.31; 'gcc': 0.31; 'object.': 0.31; 'writes:': 0.31; 'this.': 0.32; 'running': 0.33; 'cc:no real name:2**1': 0.33; 'common': 0.35; 'but': 0.35; 'everyone.': 0.36; 'false': 0.36; 'charset:us-ascii': 0.36; 'implement': 0.38; 'represent': 0.38; 'according': 0.40; 'free': 0.61; 'numbers': 0.61; 'header:Message-Id:1': 0.63; 'more': 0.64; 'to:addr:gmail.com': 0.65; '2014,': 0.84; '2015': 0.84; 'received:89': 0.85
To LJ <luisjosenovoa@gmail.com>
From Laura Creighton <lac@openend.se>
Subject Re: id() and is operator
In-Reply-To Message from LJ <luisjosenovoa@gmail.com> of "Sun, 22 Feb 2015 09:53:33 -0800." <87f18c68-120d-44f2-bd34-6f73c69365da@googlegroups.com>
References <87f18c68-120d-44f2-bd34-6f73c69365da@googlegroups.com>
MIME-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-ID <11537.1424628811.1@fido>
Content-Transfer-Encoding quoted-printable
Date Sun, 22 Feb 2015 19:13:31 +0100
Cc python-list@python.org, lac@openend.se
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.19019.1424628820.18130.python-list@python.org> (permalink)
Lines 55
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424628820 news.xs4all.nl 2845 [2001:888:2000:d::a6]:52576
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86140

Show key headers only | View raw


In a message of Sun, 22 Feb 2015 09:53:33 -0800, LJ writes:
>Hi everyone. Quick question here. Lets suppose if have the following numpy array:
>
>b=np.array([[0]*2]*3)
>
>and then:
>
>>>> id(b[0])
>45855552
>>>> id(b[1])
>45857512
>>>> id(b[2])
>45855552
>
>Please correct me if I am wrong, but according to this b[2] and b[0] are the same object. Now,
>
>>>> b[0] is b[2]
>False


You are running into one of the peculiarities of the python representation
of numbers.  It can make things more efficient to represent all common
numbers as 'there is only one' of them.

So.

  Python 2.7.9 (default, Dec 11 2014, 08:58:12)
 [GCC 4.9.2] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> a = 1
 >>> b = 1
 >>> a is b
 True
 >>> a = 1001
 >>> b = 1001
 >>> a is b
 False

--------
Don't rely on this.  Other implementations are free to implement this
however they like.
--------

[PyPy 2.4.0 with GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> a = 1001
>>>> b = 1001
>>>> a is b
True

Laura

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


Thread

id() and is operator LJ <luisjosenovoa@gmail.com> - 2015-02-22 09:53 -0800
  Re: id() and is operator Laura Creighton <lac@openend.se> - 2015-02-22 19:13 +0100
  Re: id() and is operator Chris Angelico <rosuav@gmail.com> - 2015-02-23 06:23 +1100
  Re: id() and is operator Gary Herron <gherron@digipen.edu> - 2015-02-22 11:16 -0800
  Re: id() and is operator Laura Creighton <lac@openend.se> - 2015-02-22 20:58 +0100
  Re: id() and is operator Marko Rauhamaa <marko@pacujo.net> - 2015-02-22 23:25 +0200
    Re: id() and is operator Chris Angelico <rosuav@gmail.com> - 2015-02-23 08:36 +1100
    Re: id() and is operator Terry Reedy <tjreedy@udel.edu> - 2015-02-23 01:02 -0500
      Re: id() and is operator Marko Rauhamaa <marko@pacujo.net> - 2015-02-23 08:31 +0200
    Re: id() and is operator Gary Herron <gherron@digipen.edu> - 2015-02-22 22:29 -0800
  Re: id() and is operator Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-23 12:31 +1100
  Re: id() and is operator Terry Reedy <tjreedy@udel.edu> - 2015-02-23 01:14 -0500

csiph-web