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
  • 349,597
  • 67
  • 533
  • 578
Python learner
  • 1,159
  • 1
  • 8
  • 20

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
  • 741,623
  • 53
  • 500
  • 612