Python string interning
While this question doesn’t have any real use in practice, I am curious as to how Python does string interning. I have noticed the following.
While this question doesn’t have any real use in practice, I am curious as to how Python does string interning. I have noticed the following.
>>> s1 = "spam" >>> s2 = "spam" >>> s1 is s2 True >>> q = 'asdalksdjfla;ksdjf;laksdjfals;kdfjasl;fjasdf' >>> r = 'asdalksdjfla;ksdjf;laksdjfals;kdfjasl;fjasdf' >>> q is r False How many characters should have to s1 is s2 give False? Where is limit? i.e. I am asking how long a string has to be before python starts making … Read more
In Java, explicitly declared Strings are interned by the JVM, so that subsequent declarations of the same String results in two pointers to the same String instance, rather than two separate (but identical) Strings.