python check if item in list exists code example
Example 1: how to check if any item in list is in anoter list
list_A = [1, 2, 3, 4]
list_B = [2, 3]
check = any(item in list_A for item in list_B)
print(check)
Example 2: python check if list contains
bikes = ['trek', 'redline', 'giant']
'trek' in bikes
Example 3: python check if list contains value
if value in list:
if value not in list:
Example 4: python how to check in a list
listA = ['Stranger Things', 'S Education', 'Game of Thrones']
if 'Dark' in listA:
print("Yes, 'S Eductation' found in List : ", listA)
else:
print("Nope, 'Dark' not found in the list")
Example 5: python checking not in list
a = [1, 2, 3, 4, 5, 6]
b = 7
c = 4
if b not in a:
print('True')
else:
print('False')
if c in a:
print('True')
else:
print('False')