I just found this :
a = (None,)
print (a is True)
print (a is False)
print (a == True)
print (a == False)
print (a == None)
print (a is None)
if a : print "hello"
if not a : print "goodbye"
which produces :
False
False
False
False
False
False
hello
So a neither is, nor equals True nor False, but acts as True in an if statement.
Why?
Update :
actually, I’ve just realized that this isn’t as obscure as I thought. I get the same result for a=2, as well (though not for a=0 or a=1, which are considered equal to False and True respectively)
ais a one-member tuple, which evaluates toTrue.istest identity of the object, therefore, you getFalsein all those test.==test equality of the objects, therefore, you getFalseagain.in
ifstatement a__bool__(or__nonzero__) used to evaluate the object, for a non-empty tuple it should returnTrue, therefore you getTrue. hope that answers your question.edit: the reason
TrueandFalseare equal to1and0respectively is becausebooltype implemented as a subclass ofinttype.