How to Check if a List Contains a Specific Element
In Python, you can use the in operators to check whether a specific element exists in a list.
To check whether an element is not in a list, use the not in operator.
in Operator
The in operator checks if a specific element is included in a list.
It returns True if the element exists in the list, and False if it does not.
Example of in Operator
fruits = ["apple", "banana", "cherry"] print("apple" in fruits) # True print("orange" in fruits) # False
not in Operator
The not in operator checks if a specific element is not included in a list.
It returns True if the element is not in the list, and False if it is.
Example of not in Operator
fruits = ["apple", "banana", "cherry"] print("orange" not in fruits) # True print("apple" not in fruits) # False
Quiz
0 / 1
How to check for the inclusion of a specific element in a list
Use the 'in' operator to check for the existence of a specific element in a list and print True or False.
fruits = ['apple', 'banana', 'cherry']print('orange' in )Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help
Code Editor
Run
Generate
Execution Result