is is identity testing, == 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: is is the id(a) == id(b)
manpreet
Best Answer
3 years ago
I've got a Python program where two variables are set to the value
'public'. In a conditional expression I have the comparisonvar1 is var2which fails, but if I change it tovar1 == var2it returnsTrue.Now if I open my Python interpreter and do the same "is" comparison, it succeeds.
What am I missing here?