I was experimenting with string slicing in Python, and this is the code I came up with:
s = 'a string'
print(id(s[3:]), id(s[5:]))
print(id(s[3:])==id(s[5:]))
print(s[3:] is s[5:])
print(s[3:] is s[3:])
The following are the outcomes of the code:
4396519216 4396519216
True
False
False
This website provides various instances, but I'm not sure what they mean. My question is how those string slices are stored in memory, why different slices of a string have the same id, and why do they yield 'False' when compared to using the 'is' keyword with the same id.