C: you do not check the equality between the lines, you check the equality between the objects that are resolved using pointers. So your code is:
>>> a="x" >>> b="x" >>> a is b True
does not ask: "a and b are the same character?", his query "are a and b the same object?". Since there is a small cache of objects (for small integers and one byte string, as mentioned earlier), the answer is “yes, both variables refer to the same object in memory, a small object x characters”.
When you work with an object that is not suitable for the cache, as in:
>>> a="xü" >>> b="xü" >>> a is b False
what happens is that a and b now refer to different objects in memory, so the operator allows false (a and b do not point to the same object!).
If an idea compares strings, you should use the == operator, not.
source share