0

When True is not element of the list, why it returns True?

print(True in [1,2,3])
Mohit M
  • 7
  • 2

1 Answers1

1

True is implictly converted to a number, 1. (False would be converted to 0) The in operator checks if any element is equal to the left operand, and True is equal to the first element, 1.

>>> True == 1
True
smitop
  • 4,770
  • 2
  • 20
  • 53