0
print(3 in [1, 2, 3] == [1, 2, 3])
#Output: True 

print((3 in [1, 2, 3]) == [1, 2, 3])
#Output: False

I'm just wondering what is happening here.

John Kugelman
  • 330,190
  • 66
  • 504
  • 555
Python learner
  • 1,161
  • 1
  • 6
  • 19

1 Answers1

2

Because of Python's comparison chaining feature.

3 in [1, 2, 3] == [1, 2, 3]

is treated as

(3 in [1, 2, 3]) and ([1, 2, 3] == [1, 2, 3])
Barmar
  • 669,327
  • 51
  • 454
  • 560