Table of Contents
Introduction
The membership operator of python checks for the membership of the given value in given range. Python provides the two in-built membership operators:
Identity operator | Meaning |
in | Returns True if the value is present in given sequence otherwise returns False. |
not in | Returns True if the value is not present in given sequence otherwise returns False. |
Examples
Example 1:
x = [10,9,8,7,6,5]
y = 5
if y in x:
print(“Present”)
else:
print(“Not present”)
Output:
Present
Example 2:
x = [10,9,8,7,6]
y = 5
if y not in x:
print(“Not Present”)
else:
print(“Present”)
Output:
Not Present
0 Comments