How to Check if a List Contains a Specific Element
You can use the in
operator to determine if a specific element exists in a list.
To check if an element does not exist in a list, use the not in
operator.
in Operator
The in
operator checks if a specific element is included in a list.
The in
operator returns True
if the element is in the list, and False
if it is 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
Mission
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
Publish
Design
Upload
Notes
Favorites
Help
Code Editor
Run
Generate
Execution Result