Python Two Identical Strings are viewed as Different
Question: I have two strings that by all indication look identical:

    
    
    x1 = 'N C Soft - NCSOFT_Guild Wars 2 December 2013 :: BNLX_AD_Parallax_160x600'
    x2 = 'N C Soft - NCSOFT_Guild Wars 2 December 2013 :: BNLX_CT_Parallax_160X600'
    

However, checking for equality shows they are not.

    
    
    In [312]: if x1 != x2:
       .....:     print 'yep'
       .....:
    yep
    

I also tried copying both strings out of command prompt and them pasting them
back in as a new variables but they are still not equal. I'm 80% sure it's
because they're encoded in a weird way, with some odd characters inserted that
I can't see, but using type() both just show up as string.

Is there any way I can see the "real" string? Any help is appreciated.


Answer: They are not the same; using
[`difflib.ndiff()`](https://docs.python.org/2/library/difflib.html#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()`](https://docs.python.org/2/library/functions.html#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](https://docs.python.org/3/library/functions.html#ascii) 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.

