0

I started learning python but I've noticed something unsual, something that I do not understand, why the expression provided below it's evaluated to false even it is true??

l = [1,2,3,4,5,"Hi"]
"Hi" in l  # returns True
"Hi" in l == True # returns False

J.Doe
  • 35
  • 1
  • 4

1 Answers1

4

"Hi" in l == True is evaluated as ("Hi" in l) and (l == True) which is False.

Explanation from documentation:

Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z

sanyassh
  • 7,382
  • 12
  • 27
  • 61