How to explain the first expression? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to explain the first expression?

>>> 3 in [1, 2, 3] == [1, 2, 3] True >>> (3 in [1, 2, 3]) == [1, 2, 3] False >>> 3 in ([1, 2, 3] == [1, 2, 3]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: argument of type 'bool' is not iterable

12th Jan 2022, 6:12 AM
FanYu
FanYu - avatar
1 Answer
+ 3
The operator in needs an iterable on the right side. But [1,2,3] ==[1,2,3] evals to True. First expression: [1,2,3] is truthy like all variables that are not empty, None or 0. Convince yourself and use [ ] instead [1,2,3].
12th Jan 2022, 7:07 AM
Oma Falk
Oma Falk - avatar