The is operator is used to compare the memory locations of two operands. Since strings are immutable, 's' and 's' occupy the same place in memory.
Due to how unicode is handled in python2.7, u's' and 's' are saved the same / place. Therefore, they occupy the same place in memory. Therefore, 's' is u's' evaluates to True .
As @mgilson points out, 's' and u's' are of different types and therefore do not occupy the same memory location, which leads to an 's' is u's' evaluation of False
However, when calling str(u's') , a new line is created and returned. This new line, because it is recreated, lives in a new place in memory, so the comparison of is fails.
You really want to check that they are equivalent strings, so use ==
In [1]: 's' == u's' Out[1]: True In [2]: 's' == 's' Out[2]: True In [3]: 's' == str(u's') Out[3]: True
source share