They are not the same; using difflib.ndiff() shows how these two values differ very clearly:

>>> import difflib
>>> print '\n'.join(difflib.ndiff([x1], [x2]))
- N C Soft - NCSOFT_Guild Wars 2 December 2013 :: BNLX_AD_Parallax_160x600
?                                                      ^^             ^

+ N C Soft - NCSOFT_Guild Wars 2 December 2013 :: BNLX_CT_Parallax_160X600
?                                                      ^^             ^

In general, when in doubt use repr() to look at the representation. Python 2 will use escapes for any non-printable or non-ASCII character in the string, any 'funny' characters will stand out like a sore thumb. In Python 3, use the ascii() function for the same result as repr() there is less conservative and Unicode is rife with character combinations that look the same at first glance.

For strings where you still cannot see what changes between the two, the above difflib tool can also help point out what exactly changed.

Answer from Martijn Pieters on Stack Overflow
Discussions

python - Why does comparing strings using either '==' or 'is' sometimes produce a different result? - Stack Overflow
As pointed out in previous answers, ... of strings. But this may be helpful to know if you have some kind of weird requirement to use is. Note that the intern function used to be a built-in on Python 2, but it was moved to the sys module in Python 3. ... Save this answer. ... Show activity on this post. is is identity testing and == is equality testing. This means is is a way to check whether two things are ... More on stackoverflow.com
🌐 stackoverflow.com
Strings look equal but aren't
It is probably new line characters ('\n' or '\t', etc), they become part of the string when you read lines from txt files, and they would look the same when you print them. To solve, after read lines from the txt file, use split(), this will get rid of all trailing new line characters. Edit: Sorry I meant strip(), was not getting enough coffee yesterday... More on reddit.com
🌐 r/learnpython
6
2
April 28, 2015
Python - two strings appear to be equal but are not - Stack Overflow
Use ord to reliably identify characters in a string. ... It turns out that two of the characters in the key in question had "unusual" ASCII values. When I have a string 'c', python assumes I'm referring to the character with ASCII value of 99, whereas the 'c' character in the data structure ... More on stackoverflow.com
🌐 stackoverflow.com
Python: Comparing two strings that should be the same but that are not - Stack Overflow
I'm a noob so I hope this is the right place to ask this question. This is really driving me nuts. I'm looking for a sentence in some text file, here is the partial code: SentenceIMLookingfor='blh... More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 15
1698

is is identity testing, and == is equality testing. What happens in your code would be emulated in the interpreter like this:

>>> a = 'pub'
>>> b = ''.join(['p', 'u', 'b'])
>>> a == b
True
>>> a is b
False

So, no wonder they're not the same, right?

In other words: a is b is the equivalent of id(a) == id(b)

2 of 15
672

Other answers here are correct: is is used for identity comparison, while == is used for equality comparison. Since what you care about is equality (the two strings should contain the same characters), in this case the is operator is simply wrong and you should be using == instead.

The reason is works interactively is that (most) string literals are interned by default. From Wikipedia:

Interned strings speed up string comparisons, which are sometimes a performance bottleneck in applications (such as compilers and dynamic programming language runtimes) that rely heavily on hash tables with string keys. Without interning, checking that two different strings are equal involves examining every character of both strings. This is slow for several reasons: it is inherently O(n) in the length of the strings; it typically requires reads from several regions of memory, which take time; and the reads fills up the processor cache, meaning there is less cache available for other needs. With interned strings, a simple object identity test suffices after the original intern operation; this is typically implemented as a pointer equality test, normally just a single machine instruction with no memory reference at all.

So, when you have two string literals (words that are literally typed into your program source code, surrounded by quotation marks) in your program that have the same value, the Python compiler will automatically intern the strings, making them both stored at the same memory location. (Note that this doesn't always happen, and the rules for when this happens are quite convoluted, so please don't rely on this behavior in production code!)

Since in your interactive session both strings are actually stored in the same memory location, they have the same identity, so the is operator works as expected. But if you construct a string by some other method (even if that string contains exactly the same characters), then the string may be equal, but it is not the same string -- that is, it has a different identity, because it is stored in a different place in memory.

🌐
Reddit
reddit.com › r/learnpython › strings look equal but aren't
r/learnpython on Reddit: Strings look equal but aren't
April 28, 2015 -

I've got two strings: one is a line read from a textfile. One is the result of some concatenated strings. They look the same. When I print them, they print the same. But if I compare them, Python says they are different. Any ideas why?

An example string is "IMAGE=00012n091.png"

I avoided the problem by using "in" to look for n091, but I still want to know why a straight comparison didn't work.

Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-comparison
Python Compare Strings: Methods, Operators & Best Practices | DigitalOcean
June 15, 2026 - The equality operator == is used to compare two strings in Python. It checks if the values of the strings are equal, character by character. This means that the comparison is done based on the actual characters in the strings, not their memory locations. For example: str1 = "Hello, World!" ...
🌐
Quora
quora.com › Why-are-strings-not-equal-to-each-other-even-after-comparing-using-the-operator-in-Python
Why are strings not equal to each other even after comparing using the == operator in Python? - Quora
Answer: I understand that this should give you True if both strings have the same value. Take a careful look at the string. Watch out especially whether the two strings have the same case. None of the following three strings is equal to the others, simply because the letters don’t have the ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-equals
How to Check if Two Strings Are Equal in Python (With Examples) | DigitalOcean
September 12, 2025 - You can check if two strings are equal in Python by using the == operator. This operator checks if the values of the strings are equal. ... The == operator checks if the values of two objects are equal, while the is operator checks if two objects are the same (i.e., they refer to the same memory ...
🌐
Sololearn
sololearn.com › en › Discuss › 1953992 › can-someone-tell-me-why-these-two-strings-are-not-equal
Can someone tell me why these two strings are not equal?
September 2, 2019 - Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Stack Overflow
stackoverflow.com › questions › 43108326 › python-how-is-it-possible-for-two-strings-with-the-same-value-to-not-be-the-sam
Python: How is it possible for two strings with the same value to not be the same? - Stack Overflow
I a getting errors because the servername google is not valid in the following (read from file): Copygoogle.com, 74.125.196.101 google.com, 74.125.196.138 · I have done some digging, and replacing hostname with host resolve the issue, but they are literally exactly the same string. There is absolutely no difference to the human eye with these strings, but for some reason, python says they are false:
🌐
freeCodeCamp
freecodecamp.org › news › python-compare-strings-how-to-check-for-string-equality
Python Compare Strings – How to Check for String Equality
March 18, 2022 - Note that using = would make the interpreter assume you want to assign one value to another. So make sure you use == for comparison. The != operator checks if two strings are not equal.