Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'string': 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'specific.': 0.09; 'strings.': 0.09; 'subject:How': 0.10; 'python': 0.11; 'length.': 0.16; 'subject:python': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'print': 0.22; 'header:User-Agent:1': 0.23; 'received:emailsrvr.com': 0.24; "i've": 0.25; 'compare': 0.26; 'received:(smtp server)': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'gary': 0.31; "skip:' 40": 0.31; 'yes.': 0.31; 'google': 0.35; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'new': 0.61; 'kind': 0.63; 'details': 0.65; 'direct': 0.67; 'determine': 0.67; 'of:': 0.68; 'subject:know': 0.84 X-Virus-Scanned: OK Date: Wed, 12 Feb 2014 13:02:03 -0800 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How does python know? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392239501 news.xs4all.nl 2936 [2001:888:2000:d::a6]:59341 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66088 On 02/12/2014 12:17 PM, Tobiah wrote: > I do this: > > a = 'lasdfjlasdjflaksdjfl;akjsdf;kljasdl;kfjasl' > b = 'lasdfjlasdjflaksdjfl;akjsdf;kljasdl;kfjasl' > > print > print id(a) > print id(b) > > > And get this: > > True > 140329184721376 > 140329184721376 > > > This works for longer strings. Does python > compare a new string to every other string > I've made in order to determine whether it > needs to create a new object? > > Thanks, > > Tobiah Yes. Kind of: It's a hash calculation not a direct comparison, and it's applied to strings of limited length. Details are implementation (and perhaps version) specific. The process is called "string interning". Google and wikipedia have lots to say about it. Gary Herron