On Sun, Jan 16, 2022 at 6:34 PM Chris Angelico <ros...@gmail.com> wrote:
> > def fun(): > > return "some string" > > > > doesn't return the same string, unless it's iterned, which is an > implementation detail, yes? > > Not sure what you mean. That's a constant, so it'll always return the > exact same object, surely? > I *think* that's only if it's interned -- and in any case, is a guarantee of the language, or an optimization? I tried to test with a longer string, and it was the same one, but then I found in this arbitrary post on the internet: ... in Python 3.7, this has been changed to 4096 characters ( I guess I haven't played with that since 3.7) -- I haven't actually tried with a string literal linger than 4096 chars :-) But this certainly doesn't: In [1]: def fun(): ...: return [1,2,3] ...: In [2]: l1 = fun() In [3]: l2 = fun() In [4]: l1 is l2 Out[4]: False So the issue is immutability and interning, not "literal display". My point is that a frozenset litteral could open the door to interning frozen sets, but that could probably be done anyway. And why? Are they heavily used in any code base? -CHB -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ 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/SM2SBPTFFEK7I6AHEEXYKZWRNLC4G3J7/ Code of Conduct: http://python.org/psf/codeofconduct/