How Can We Help?
Introduction:
In this tutorial, we are going to explain how to use Python tuple membership operators with basic syntax and many examples for better understanding.
Python tuple membership operators (‘in’ & ‘not in’) is used to check whether the value is a part of given tuple or not.
Syntax:
<tuple_element> in <tuple_variable_name>
<tuple_element> not in <tuple_variable_name>
Input Parameters:
- tuple_element : the tuple element that we want to check the existence in the tuple.
- tuple_variable_name : The tuples that we want to check whether a given tuple_element is available or not.
tuple 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 tuple variable ‘number’ and get the output as True as value 3 is available in tuple ‘number’.
tuple 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 tuple variable ‘number’ and get the output as True as value 10 is not available in tuple ‘number’.
In this tutorial, you have learned how to check whether particular value is a membership of a tuple 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 tuples.
- Repetition(‘*’) : It repeats element of tuple.
- tuple Iteration : It returns element of tuple by using for loop with tuple.
Python tutorials list:
- Python tutorials list : access all python tutorials.