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: 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 From: Laura Creighton Subject: Re: id() and is operator In-Reply-To: Message from LJ 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 nump= y array: > >b=3Dnp.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 =3D 1 >>> b =3D 1 >>> a is b True >>> a =3D 1001 >>> b =3D 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 =3D 1001 >>>> b =3D 1001 >>>> a is b True Laura