Python 'is' operator for two long strings

123 views Asked by At
a = 'This is a very long string. This is a very long string. No?'
b = 'This is a very long string. This is a very long string. No?'

print(id(a), id(b))
print(a is b)

On my computer, the results are:

4467772080 4467772080
True

As I know Python only caches short strings. But why such a long string, it still keeps only one copy? In fact, I changed it to be a very long string (even longer than 1024), a and b are still pointing to the same string object. Please correct me where I am wrong?

0

There are 0 answers