0
List operation
Whatâs different x = [42, 8, 7, 1, 0, 124, 8897, 555, 3, 67, 99] num = int(input()) Between them? if num in x : print('bingo') if x in num: print('bingo')
2 Answers
+ 5
Num is a single entity, while x is a list of entities.
'If x in y' will run through every entity in y, and see if x is found.
In your first example (if num in x) it will check and see if the number input is in the list.
In the second example, it is trying to see if the list is in your integer, which will generate a TypeError
+ 1
You cannot check if a list is inside an int, but you can ask if a list is inside a list.
lst_a = [1, 2, 3, 4]
lst_b = [11, 12, 13, 14]
lst_c = [lst_a, lst_b]
if lst_a in lst_c:
print(True)
else:
print(False)
It prints True.