Can't match str/unicode

Steve D'Aprano steve+python at pearwood.info
Sat Jan 7 19:58:51 EST 2017


On Sun, 8 Jan 2017 08:40 am, CM wrote:

> So what's going on here? Why isn't a string with the content 'match' equal
> to another string with the content 'match'?

You don't know that the content is 'match'. All you know is that when
printed, it *looks like* 'match'.

Hint:

s = 'match '
print 'match', s  # they look the same
print 'match' == s  # but they aren't the same


Start by printing repr(candidate_text) and see what you really have.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.



More information about the Python-list mailing list