is comparison returns False with strings using same id
<p>I was playing around with Python <code>is</code> and <code>==</code> operator. As far as I know, is operator checks whether two objects have same id, but in my case operator returns False even if two substrings have the same id. </p>

<p>Here is the code:</p>

<pre><code>#! /usr/bin/python3
# coding=utf-8
string = "HelloWorld"

print(id(string))    #140131089280176
print(id(string[0:5]))  #140131089251048
print(id(string[-10:-5]))   #140131089251048


print(string[0:5] == string[-10:-5])    #True
print(string[0:5] is string[-10:-5])    #False
</code></pre>

<p>Substrings do not have same id with the original string as expected, but why is operator returns false with 2 substrings with the same id?</p>

<p>For me both:</p>

<pre><code>print(id(string[0:5]))
print(id(string[-10:-5]))  
</code></pre>

<p>have different IDs, and as such, those answers:</p>

<pre><code>print(string[0:5] == string[-10:-5])    #True
print(string[0:5] is string[-10:-5])    #False
</code></pre>

<p>Are as they should be expected.</p>

<p>Are u sure u didnt make mistake here?</p>

<p># I would post that as a comment, but cant yet</p>

python string comparison