What is Python Identity Operator?


The memory locations of two objects are compared using identity operators. Below are two Identity operators that will be explained.

 Identity Operator in Python examples

Code :

x = ["red",”blue”]

y = ["yellow", "orange",”red”]

z=x

print(x is y)

print(x is z)

print(x is not y )

Output:

False

True

True 

What is Python Membership Operator?

Members of a sequence, such as strings, lists, or tuples, are tested using Python’s membership operators. As mentioned below, there are two membership operators.

membership operators python exmples

Code:

x = ["red",”blue”]

print(“red“ in x )

print(“yellow” not in x)

Output:

True

True 


Leave a Reply

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