When evaluating logical expressions containing and , we must evaluate the expressions that are present on both sides of the and operator. If for the or operator, if the first expression is True, then there is no need to verify the correctness of the second expression
For example, evaluating the expression 2>2 and 3==3 , you first need to check whether the first expression 2>2 True or not. If this first expression is False, then there is no need to check the second expression because of the and operator, and the result of this expression will be FALSE, since the first expression is FALSE. If the expression was 2==2 AND 3==3 , then, since the first expression 2==2 is True, we do not need to check the correctness of the second expression, and since the second expression is also true here, we get TRUE as output.
In nan and True , since nan is True and because of the and operator, python now evaluates the second expression and returns the value of the second expression. So here you get TRUE as output. The same logic, when applied to True and nan , you can expect nan as output.
The or operator is enough if we look at the first expression, so " True or nan will return True
Nakamura
source share