str_1="Hello"
str_2="Hello"
print(str_1 is str_2)
str_3="Hello World"
str_4="Hello World"
print(str_3 is str_4)
Output:
True
False
In the code snippet above, str_1
and str_2
have the same values and they share the same address in the memory. str_3
and str_4
also have the same values but they do not share the same address in the memory.
What might be reason behind this?