In this article, we will discuss how to check an item in a Python list. To check an item in the list, we can use the in operator in Python.
Syntax of in operator
item in list
Examples
a = [15,30,27,11,5,2]
print(5 in a)
Output
True
fruits = ["apple","orange","mango"]
if "mango" in fruits:
print("mango found!")
Output
mango found!
The in operator can be used with strings or tuple.
Conclusion
In conclusion, in Python, it is easy to check an item in the list using the in operator.