I had some problems getting this to work:
# Shortened for brevity
def _coerce_truth(word):
TRUE_VALUES = ('true','1','yes')
FALSE_VALUES = ('false','0','no')
_word = word.lower().strip()
print "t" in _word
if _word in TRUE_VALUES:
return True
elif _word in FALSE_VALUES:
return False
I discovered:
In [20]: "foo" is "Foo".lower()
Out[20]: False
In [21]: "foo" is "foo".lower()
Out[21]: False
In [22]: "foo" is "foo"
Out[22]: True
In [23]: "foo" is "foo".lower()
Out[23]: False
Why is this? I understand that identity is different then equality, but when is identity formed? Statement 22 should be False
unless, due to the static nature of strings, id == eq. In this case I'm confused by statement 23.
Please explain and thanks in advance.