search

How to check if an item exists in a list in Python?

 In Python, you can check if an item exists in a list using the **in** keyword. The **in** keyword returns **True** if the item is in the list, and **False** if it is not. For example:

my_list = [1, 2, 3, 4, 5]
print(3 in my_list) # Output: True
print(6 in my_list) # Output: False

You can also use the **not in** keyword to check if an item does not exist in a list:

my_list = [1, 2, 3, 4, 5]
print(6 not in my_list) # Output: True

Related Questions You Might Be Interested