Identity operators

  • The identity operator is used to compare the objects, returns True if both variables are the same object, and also returns True if both variables are not the same object.
  • This identity operator is two types:
    • is
    • is not

Identity is operators

  • Identity is operator Returns True if both variables are the same object otherwise it returns false.
Example

Identity is operators

x = ["aman", "ravi"]
y = ["aman", "ravi"]
z = x

print(x is y)

# returns True because y is the same object as x

Output

True

Identity is not operators

  • Identity is operator Returns True if both variables are NOT the same object otherwise it returns false.
Example

Identity is not operators

x = ["aman", "ravi"]
y = ["aman", "ravi"]
print(x is not y)

# returns True because x is the same object as y, even if they have the same content

Output

True
English Hindi