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


Groups > comp.lang.python > #66133

Re: How does python know?

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: How does python know?
Date 2014-02-12 20:54 -0500
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-98A4D3.20542312022014@news.panix.com> (permalink)
References <lFQKu.455927$cZ.440055@fx31.iad>

Show all headers | View raw


In article <lFQKu.455927$cZ.440055@fx31.iad>, Tobiah <toby@tobiah.org> 
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?

Yes[*].  It's called interning.  See 
https://en.wikipedia.org/wiki/Intern_(computer_science).

[*] Well, nothing requires Python to do that.  Some implementations do.  
Some don't.  Some do it for certain types of strings.  Your mileage may 
vary.

Back to comp.lang.python | Previous | NextPrevious 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