check if a value exists in list python code example

Example 1: Check if element in list Python

listA = [item1, item2, item3]
if item4 in listA:
  print('yes, item4 is in the list')
else:
  print('no, item4 is not in the list')

Example 2: check if a number is in a list python

5 in [3, 4, 5, 6, 7]
# True

9 in [3, 4, 5, 6, 7]
# False

Example 3: python find if part of list is in list

'''    
    check if list1 contains all elements in list2
'''
result =  all(elem in list1  for elem in list2)
if result:
    print("Yes, list1 contains all elements in list2")    
else :
    print("No, list1 does not contains all elements in list2"