
Data Structures 2.7
checkin.py
shopping_list = ["Milk", "Bread", "Chocolate spread", "Eggs"]
check = "Eggs" in shopping_list
print(check)
check = "Milk" in shopping_list
print(check)
check = "mango" in shopping_list
print(check)
check = "eggs" in shopping_list
print(check)
check = "Bread" in shopping_list
print(check)
python checkin.py
True
True
False
False
True
You can check for an existing item in a list using the keyword in. In the above program,
the variable check is reassigned multiple times and printed using print().
[To test whether a value is in the list, use in, which returns True if the value is
found or False if it is not.]
Finding the ...