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!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'suppose': 0.07; 'beginners': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrong,': 0.09; 'jan': 0.12; 'comparison.': 0.16; 'ctypes.': 0.16; 'ids.': 0.16; 'numpy': 0.16; 'objects.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'retry': 0.16; 'ignore': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'certainly': 0.24; 'lets': 0.24; 'question': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'correct': 0.29; 'appreciated.': 0.29; 'generally': 0.29; 'properties': 0.29; '>>>>': 0.31; 'explained': 0.31; 'object.': 0.31; 'text': 0.33; 'objects': 0.35; 'but': 0.35; 'are,': 0.36; 'everyone.': 0.36; 'false': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'according': 0.40; 'skip:u 10': 0.60; 'different': 0.65; 'touch': 0.74; 'experiment': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: id() and is operator Date: Mon, 23 Feb 2015 01:14:03 -0500 References: <87f18c68-120d-44f2-bd34-6f73c69365da@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-98-114-97-173.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 In-Reply-To: <87f18c68-120d-44f2-bd34-6f73c69365da@googlegroups.com> 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424672057 news.xs4all.nl 2932 [2001:888:2000:d::a6]:45342 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86194 On 2/22/2015 12:53 PM, LJ wrote: > 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, You are, as other explained > but according to this b[2] and b[0] are the same object. >>>> b[0] is b[2] > False > > Any clarification is much appreciated. In Python, 'two' objects can only be the same thing if they exist simultaneously. Retry your experiment with simultaneous objects. >>> b0 = b[0] >>> b1 = b[1] >>> b2 = b[2] # etc. The three objects will have different ids. The mail purpose of the id function is to text properties of a particular implementation. It also has uses with ctypes. Beginners should generally ignore it, and certainly not touch it until reading and understanding its doc. The main use for 'is' is for 'is None' comparison. -- Terry Jan Reedy