Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66088

Re: How does python know?

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 <gary.herron@islandtraining.com>
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 <gary.herron@islandtraining.com>
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 <lFQKu.455927$cZ.440055@fx31.iad>
In-Reply-To <lFQKu.455927$cZ.440055@fx31.iad>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6786.1392239501.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How does python know? Tobiah <toby@tobiah.org> - 2014-02-12 12:17 -0800
  Re: How does python know? Tobiah <toby@tobiah.org> - 2014-02-12 12:27 -0800
    Re: How does python know? Dave Angel <davea@davea.name> - 2014-02-12 16:59 -0500
  Re: How does python know? Chris Angelico <rosuav@gmail.com> - 2014-02-13 07:33 +1100
  Re: How does python know? Gary Herron <gary.herron@islandtraining.com> - 2014-02-12 13:02 -0800
  Re: How does python know? Roy Smith <roy@panix.com> - 2014-02-12 20:54 -0500

csiph-web