A senior of mine demonstrated it and I want to know if this is a flaw or is there some precedence and operator associativity stuff that justifies it.
>>> False==False in [False] True
False == (False or True) In this expression python would first solve the comparison operator in bracket. => (False or True) is said to be True. Because the 'OR' operator search for the first truthy value, and if found it returns the value else 'False'. Now we have: =>False == True is False.
If the left side of the expression is "falsey", the expression will return the left side. If the left side of the expression is "truthy", the expression will return the right side. That's it. So in false && false , the left side is "falsey", so the expression returns the left side, false .
The true operator returns the bool value true to indicate that its operand is definitely true. The false operator returns the bool value true to indicate that its operand is definitely false.
adjective, fals·er, fals·est. not true or correct; erroneous: a false statement. uttering or declaring what is untrue:a false witness. not faithful or loyal; treacherous: a false friend. tending to deceive or mislead; deceptive: a false impression.
Python's comparison operators chain.
False == False in [False]
is evaluated as
(False == False) and (False in [False])
The middle term participates in both comparisons.
I would prefer that in
not chain with the other comparison operators.
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