Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
community creator

What are membership operators in Python?

Saketh Jaggaiahgari

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

Code

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

python
community creator
RELATED COURSES

View all Courses

Keep Exploring