Note: Before you go and downvote or close my question, or mark it a duplicate, let me assure you that I have looked a dozens and dozens of similar questions on SO and Googled but after more than an hour, I still haven't solved this problem. No other answer solved my problem.
Question I have this Python code:
text = ''
text += '<' + '/' + '>'
print text, '</>'
print repr(text), repr('</>')
if text is '</>':
print 'Equal'
else:
print 'Not equal!'
I simply want to compare two strings. For some reason, I need to concatenate characters to text one by one. I expected the if-statement to evaluate to True but it doesn't. And I am at a loss why!
Here's the output:
</> </>
'</>' '</>'
Not equal!
I am new to Python, and am using Python 2.7. Can anybody help, please?
isand==, which is why I never found this post.ischeck for the object identity, that is the direction in memory of the object not the value they contain, for that use==. Only the build-in constants are guaranty to evaluate the same withisand==that is why you see will stuff likea is Nonemore often thata == Nonebecause the former is more idiomatic. So unless you are checking forNoneor if they are located in the same place (aka the point to the same thing) in memory, use==