Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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; 'subject:: [': 0.03; 'cpython': 0.05; 'objects,': 0.07; 'subject:question': 0.08; 'alter': 0.09; 'etc).': 0.09; 'flags,': 0.09; 'modulo': 0.09; 'objects.': 0.09; 'to)': 0.09; 'aug': 0.13; 'also:': 0.16; 'constants': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ids.': 0.16; 'least,': 0.16; 'time).': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'appears': 0.18; '(or': 0.18; 'subject:] ': 0.19; 'fairly': 0.21; 'received:209.85.214.174': 0.21; 'occurs': 0.22; 'header:In-Reply-To:1': 0.25; 'compiled': 0.27; 'scale': 0.27; 'module.': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'fri,': 0.30; 'point': 0.31; 'subject:lists': 0.32; 'could': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'false': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'possible': 0.37; 'two': 0.37; 'received:209': 0.37; 'things': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'course.': 0.62; 'different': 0.63; 'more': 0.63; 'potentially': 0.66; 'believe': 0.69; 'etc,': 0.84; 'factors,': 0.84; 'angel': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=6FtERTjGyEL0Hx0hRGimv/PA8eA/nBoC++eoOlTQ0vs=; b=WUympqE5RtZhzR177voTS1seqZWeXaJu3DqmUmWgEM8p2Rit3odQTO/VakQe7ancbx vi+sUTKh/ueIuUnBUtWXRC3AcjkryNc12URI/vJHiRupzrp5Rmh1Is5OONRW5dtJ/xDb 3UTi16BOfVepxdcJZ2A5N2qt7y0+eCn0GEaQRxSLJeYsGRvmjipiHFVWVXO9fcMEWFnk A4CEhEiIIlJHhb+ICyjYrVT1A5dI/6kjU0eV7cUveoxYUt2ACidK251m7mwXd5fL7/SH v7KU5P2WhFvofvroCQ3ypWFITMedrVUPKTfdTn3GNuKO+Emvf9P7WlZuBF4MTj2xOHGQ Pszw== MIME-Version: 1.0 In-Reply-To: <5024E8CC.9020703@davea.name> References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> <5024E8CC.9020703@davea.name> Date: Fri, 10 Aug 2012 21:00:40 +1000 Subject: Re: [newbie] A question about lists and strings From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344596444 news.xs4all.nl 6932 [2001:888:2000:d::a6]:47844 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26864 On Fri, Aug 10, 2012 at 8:56 PM, Dave Angel wrote: >> On Fri, Aug 10, 2012 at 8:07 PM, Dave Angel wrote: >>> But if you said c=651 and d=651, you'd have two >>> objects, and the two names would be bound to different objects, with >>> different ids. >> To be more accurate, you *may* have two different objects. It's >> possible for things to be optimized (eg with small numbers, or with >> constants compiled at the same time). > > You're right, of course. But I picked the value of 650+ deliberately, > as I believe CPython doesn't currently optimize ints over 256. Yep. Also: >>> a=651; b=651 >>> a is b True >>> a=651 >>> a is b False Same thing occurs (or at least, appears to) with constants in the same module. Could potentially be a fairly hefty optimization, if you use the same numbers all the time (bit flags, scale factors, modulo divisors, etc, etc, etc). Still doesn't alter your fundamental point of course. ChrisA