<br><br><div class="gmail_quote">On Mon, Jan 10, 2011 at 8:54 AM, bob gailer <span dir="ltr">&lt;<a href="mailto:bgailer@gmail.com">bgailer@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 1/10/2011 11:07 AM, Karim wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
s =&#39;xyz&#39;<br>
&gt;&gt;&gt; t = str(&#39;xyz&#39;)<br>
<br>
&gt;&gt;&gt; id(s) == id(t)<br>
True<br>
<br>
Thus if I create 2 different instances of string if the string is identical (numerically).<br>
</blockquote>
<br></div>
Python &quot;interns&quot; certain literal strings - so a 2nd attempt to create &#39;xyz&#39; will refer back to the original object.<br></blockquote><div><br></div><div><br></div><div>i haven&#39;t researched all the rules for strings either, but from my understanding, they&#39;re short(er) strings which are used often enough to warrant interning.</div>
<div><br></div><div>the (current) rule for ints is: range(-5, 257). i say current because before 2.5, it was range(-1, 101). no one bothered to tell me when i updated Core Python to a 2nd ed. good thing i checked before it went to press! :P</div>
<div><br></div><div>note that floats are also immutable, but they&#39;re never interned, so you&#39;ll never get the same one twice unless you&#39;re really referring to the same object. same goes for complex, etc. interning is strictly for commonly-used small ints and short strings.</div>
</div><div><br></div>cheers,<br>-- wesley<br>- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>&quot;Core Python Programming&quot;, Prentice Hall, (c)2007,2001<br>&quot;Python Fundamentals&quot;, Prentice Hall, (c)2009<br>
    <a href="http://corepython.com">http://corepython.com</a><br><br>wesley.j.chun :: <a href="http://wescpy-at-gmail.com">wescpy-at-gmail.com</a><br>python training and technical consulting<br>cyberweb.consulting : silicon valley, ca<br>
<a href="http://cyberwebconsulting.com">http://cyberwebconsulting.com</a><br>