Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'interpreter': 0.04; 'lines,': 0.05; 'differently': 0.07; 'objects,': 0.07; 'ok.': 0.07; 'python': 0.09; 'behave': 0.09; 'happens.': 0.09; 'integers': 0.09; 'mode,': 0.09; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'least,': 0.16; 'said.': 0.16; 'sorts': 0.16; 'stored.': 0.16; 'tuple)': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'integer': 0.17; '(in': 0.18; '>>>': 0.18; 'aspect': 0.22; "python's": 0.23; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'in.': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'this?': 0.28; 'mode': 0.30; 'lists': 0.31; 'subject:lists': 0.32; 'print': 0.32; "aren't": 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'something': 0.35; 'next': 0.35; 'really': 0.36; 'created': 0.36; 'but': 0.36; 'totally': 0.36; 'anything': 0.36; 'thank': 0.36; 'display': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'things': 0.38; 'gives': 0.39; 'instead': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'help': 0.40; 'your': 0.60; 'matter': 0.61; 'different': 0.63; 'else.': 0.65; 'answer.': 0.71; '2013': 0.84; 'retention': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=Sa9OnXo7qUtCG5kG0TfP8tJmQ2cvGeQStJml0iI4xyE=; b=hBxVMf1Gjv3CBElbyXVdboB8R7Co01odgNpuuKyiGcVAAiwXrNh7eyTsc71mz4okmY NSZaUnlAFevo2vR4tjJFZS+HqycaFSMopJMIpPdL3gcTLgf73kNWzwxB/mnygxY/xtk5 lI6cf8Ikn/mNnvIiXPMvmRca/3GG7BoaWxsfK2MsJzm5MHIKCsRTW7dHhHMOQzup0hgD rNtoJjmokAwVFICUnUkBCpWhjumfh5CRxZlrIt7YWLSbbp9TyT/5HP58/CAgT1OB1k3j Q8nLihfUstyUQxqUJWLyNCpAl1+NwaeGc8nscIKa4bI76p2OkJ7/0kekygFZumppMet0 WDNQ== MIME-Version: 1.0 X-Received: by 10.220.103.7 with SMTP id i7mr16438895vco.7.1363552491980; Sun, 17 Mar 2013 13:34:51 -0700 (PDT) In-Reply-To: <51a8f122-82a2-4eb0-9b8f-50d011591ae1@googlegroups.com> References: <8e66719c-5e90-4776-bba9-a11c29fba2f1@googlegroups.com> <51a8f122-82a2-4eb0-9b8f-50d011591ae1@googlegroups.com> Date: Mon, 18 Mar 2013 07:34:51 +1100 Subject: Re: tuple of ids of integers or lists From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363552494 news.xs4all.nl 6843 [2001:888:2000:d::a6]:48906 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41371 On Mon, Mar 18, 2013 at 7:23 AM, wrote: > OK. Now I understand it. > > I was confused because when two list are created in two different lines, = Python gives them different ids, but when the two lists are created in the = same line (in a tuple) Python gives them the same id. It doesn't really mat= ter as these lists are just created and destroyed, as you have said. > > Thank you very much for your fast answer. Here's something that'll either help you understand another aspect of Python, or totally do your head in. >>> print(id([3])) 14485504 >>> print(id([3])) 14485504 If you print it to stdout, the id can be reused! How is this? Here's what's going on. In interactive mode, the result of the last expression is made available under the name _ (a single underscore): >>> id([3]) 15597160 >>> _ 15597160 Integers are objects, like everything else. (Some of them are pre-made, but big numbers like this aren't - at least, not in this Python. But that's implementation-dependent too.) The retention of this integer object can in some circumstances change where the next object is stored. So you may find that some things behave differently in interactive mode than in a script; or perhaps printing something out instead of letting the interpreter display it will change what happens. You're looking into some extremely unspecified behaviour, here, so anything is allowed to affect it. Which means you might be able to learn all sorts of things about Python's internals! :) ChrisA