Other languages, like C and Java, do not have membership operators. These membership operators test for membership of an element in strings, lists, or tuples.
There are two membership operators in the Python Language:
Operator | Description | Example |
---|---|---|
in | It evaluates true if it detects a variable in the sequence; else, it returns false | a in list b results in a 1 if a is part of b |
not in | It evaluates true if it doesn’t detect a variable in the sequence; else, it returns false | a not in list b results in a 1 if a is not a part of b |
lst = [10 , 20, 30, 40, 50] print(lst) if 10 in lst: print("10 is available in the given list") else: print("10 is not available in the given list") if 12 not in lst: print("12 is not available in the given list") else: print("12 is available in the given list")
RELATED TAGS
CONTRIBUTOR
View all Courses