Membership Operators in Python

by | Aug 7, 2021 | Python

Home » Python » Membership Operators in Python

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 operatorMeaning
inReturns True if the value is present in given sequence otherwise returns False.
not inReturns 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

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author