2

enter image description here

The question is simple

>>> bull = False in [False] #Assigning value
>>> False == False in [False] #Note: Comparision is True
True
>>> False == bull #Que: Why not True?
False
>>>

I'm looking for an explanation for the above I mean what exactly is going on as I assign the same to bull what I'm trying in the coming next lines....

These threads do not answer my questions as I'm looking for simple False and True assignment and comparison statements.

It is going to question mark what I learned in maths what they called transitivity, symmetry, and reflexivity?

Darshan P.
  • 176
  • 7
  • What does `False is bull` return? – S3DEV Feb 06 '22 at 19:28
  • Also similar: [Strange chained comparison](https://stackoverflow.com/q/58084423/11082165) and [Why does the expression 0 < 0 == 0 return False in Python](https://stackoverflow.com/q/6074018/11082165) – Brian Feb 06 '22 at 19:32
  • @Brian can you please explain how your suggested links are going to answer my question? Will you please elaborate? – Darshan P. Feb 06 '22 at 19:34
  • @S3DEV `False is bull>>> False` – Darshan P. Feb 06 '22 at 19:34
  • 1
    TL;DR: thanks to [comparison operator chaining](https://docs.python.org/3/reference/expressions.html#comparisons) `(A == B in C)` is evaluated as `(A == B) and (B in C)`. – Brian Feb 06 '22 at 19:34
  • @Brian Yes, I went through the [documentation](https://docs.python.org/3/reference/expressions.html#comparisons) it's there in the answer of one of your suggested [threads](https://stackoverflow.com/questions/6074018/why-does-the-expression-0-0-0-return-false-in-python)..... – Darshan P. Feb 06 '22 at 19:36
  • @Brian If it's duplicate, You can add your answer sorry but your threads do not answer my question I'm looking for the explanation which uses `False` and `True`? – Darshan P. Feb 06 '22 at 19:46
  • 1
    @DarshanP. If you think your question should be reopened, you can follow the steps at [What can I do when I think my question's not a duplicate?](https://meta.stackoverflow.com/q/252252/11082165). In this case, it seems that the only confusion is because of the behavior of chained comparison operators, so I think the canonical dupe fits. Specific to your question, `False == False in [False]` is evaluated as `(False == False) and (False in [False])` which is True. It is not evaluated as the same as `False == bull`, which is equivalent to `False == (False in [False])`. – Brian Feb 06 '22 at 19:54
  • @Brian instead of reading [What can I do when I think my question's not a duplicate?](https://meta.stackoverflow.com/q/252252/11082165) I better would like to read the Python documentation anyways thanks for the explanation which explains how and what is happening instead of why its happening the way it is happening – Darshan P. Feb 06 '22 at 20:02

0 Answers0