<br><br><div class="gmail_quote">On Mon, Jan 10, 2011 at 8:54 AM, bob gailer <span dir="ltr"><<a href="mailto:bgailer@gmail.com">bgailer@gmail.com</a>></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 ='xyz'<br>
>>> t = str('xyz')<br>
<br>
>>> 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 "interns" certain literal strings - so a 2nd attempt to create 'xyz' will refer back to the original object.<br></blockquote><div><br></div><div><br></div><div>i haven't researched all the rules for strings either, but from my understanding, they'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're never interned, so you'll never get the same one twice unless you'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>"Core Python Programming", Prentice Hall, (c)2007,2001<br>"Python Fundamentals", 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>