On Wed, Dec 04, 2019 at 07:11:39PM +1300, Greg Ewing wrote: > On 4/12/19 12:53 pm, Soni L. wrote: > >Okay, sometimes it's also used for that. But the main use-case is for > >lowering RAM usage for immutable objects. > > Citation needed. If that's true, why does Python intern > names used in code, but not strings in general?
py> s = "ab1234z" py> t = "ab1234z" py> s is t True CPython doesn't *just* intern names. Nor does it intern every string. But it interns a lot of strings which aren't used as names, including some which cannot be used as names: py> a = "+" py> b = "+" py> a is b True It also interns many ints, and they can't be used as names at all. Here's a good explanation of interning in Python 2.7, including a great example of how interning strings can reduce memory usage by 68%. http://guilload.com/python-string-interning/ -- Steven _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/H6WOEL5CJ67P36AE3H425EDY4MGWE7K2/ Code of Conduct: http://python.org/psf/codeofconduct/