On Sat, 09 Nov 2013 09:37:54 -0500, Roy Smith wrote: > In article <mailman.2283.1383985583.18130.python-l...@python.org>, > Chris Angelico <ros...@gmail.com> wrote: > >> Some languages [intern] automatically for all strings, others (like >> Python) only when you ask for it. > > What does "only when you ask for it" mean?
In Python 2: help(intern) In Python 3: import sys help(sys.intern) for more info. I think that Chris is wrong about Python "only" interning strings if you explicitly ask for it. I recall that Python will (may?) automatically intern strings which look like identifiers (e.g. "spam" but not "Hello World" or "123abc"). Let's see now: # using Python 3.1 on Linux py> s = "spam" py> t = "spam" py> s is t True but: py> z = ''.join(["sp", "am"]) py> z is s False However: py> u = "123abc" py> v = "123abc" py> u is v True Hmmm, obviously the rules are a tad more complicated than I thought... in any case, you shouldn't rely on automatic interning since it is an implementation dependent optimization and will probably change without notice. -- Steven -- https://mail.python.org/mailman/listinfo/python-list