How Can We Help?
Introduction:
In this tutorial, we are going to explain how to use Python list membership operators with basic syntax and many examples for better understanding.
Python list membership operators (‘in’ & ‘not in’) is used to check whether the value is a part of given list or not.
Syntax:
(list_element) in (list_variable_name)
(list_element) not in (list_variable_name)
Input Parameters:
- list_element : the list element that we want to check the existence in the list.
- list_variable_name : The lists that we want to check whether a given list_element is available or not.
List membership (in) operator Example (1)
number=[1,2,3]
# using membership operator
print( ' 3 in number:', 3 in number)
Output of example 1
3 in number: True
In the above Example, using membership operator (in), we have checked whether 3 is a part of list variable ‘number’ and get the output as True as value 3 is available in list ‘number’.
List membership (not in) operator Example (2)
number=[1,2,3]
# using membership operator
print( ' 10 is not in number:', 10 not in number)
Output of example 2
10 is not in number: True
In the above Example, using membership operator (not in), we have checked whether 10 is not a part of list variable ‘number’ and get the output as True as value 10 is not available in list ‘number’.
In this tutorial, you have learned how to check whether particular value is a membership of a list in python or not ?.
If you have an inquiry or doubt don’t hesitate to leave them in comment. we are waiting your feedback.But remember to understand the concept very well, you need to practice more.
Hopefully, it was clear and concise.
Similar Python operators:
- Concatenation(‘+’) : It adds two lists.
- Repetition(‘*’) : It repeats element of list.
- List Iteration : It returns element of list by using for loop with list.
Python tutorials list:
- Python tutorials list : access all python tutorials.