Membership operators in python with example

OperatorDescriptionExample
inReturns True if a sequence with the specified value is present in the objectx in y
not inReturns True if a sequence with the specified value is not present in the objectx not in y

x = 24
y = 20
list = [15, 20, 35, 40, 50]

if (x not in list):
	print("x is NOT present in given list")
else:
	print("x is present in given list")

if (y in list):
	print("y is present in given list")
else:
	print("y is NOT present in given list")

Output
x is NOT present in the given list
y is present in the given list

Keywords:

membership operators in python with an example,
Python Membership Operators,
What is membership operator explain with example?,
What are membership operators in the list in Python?,
Python Membership and Identity Operators,
What are membership operators in Python,
What are membership operators in Python?,

Spread the love

Leave a Comment

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

Scroll to Top