Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does False==False in [False] return True? [duplicate]

Tags:

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 
like image 920
Satwik Avatar asked Dec 08 '15 18:12

Satwik


People also ask

Is false == 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.

Why is false && true 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 .

What does false || true return?

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.

What does false false mean?

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.


1 Answers

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.

like image 79
Steven Rumbalski Avatar answered Nov 19 '22 13:11

Steven Rumbalski