Going a bit mental here trying to work out what this does in python:
print "word" in [] == False
Why does this print False
?
Perhaps a more clear example of this unusual behaviour is the following:
>>> print 'word' in ['word']
True
>>> print 'word' in ['word'] == True
False
Your example is equivalent to:
print ("word" in []) and ([] == False)
This is because two boolean expressions can be combined, with the intention of allowing this abbreviation:
a < x < b
for this longer but equivalent expression:
(a < x) and (x < b)
Just like you can chain operators in 23 < x < 42
, you can do that with in
and ==
.
"word" in []
is False
and
[] == False
evaluates to False
. Therefore, the whole result is
"word" in [] == False
"word" in [] and [] == False
False and False
False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With