Python Identity Operators

python-logical-operators

Identity Operators in Python.

In the Python programming language, identity operators are used to check if both values, variables, or constants are not only the same, but also have the same memory location.
To compare and check the exact match of values between two objects, these types of operators are used.

All  Identity operators in python are discussed below  in detail with their syntax and proper example:

1. Is

It is used testify whether two variables refer to the same object. It returns True if both the objects are the same objects else it returns False. It even returns False if both objects are equal but not refer to the same object.

Syntax

Variable1 is Variable2

Example

>>> a = 10
>>> b = 10
>>> a is b
True
>>> a is 10
True
>>> 10 is 10
True

2. Is Not

It is used testify whether two variables refer to the same object. It returns False if both the objects are the same objects else it returns True. It even returns True if both objects are equal but not refer to the same object.

Syntax

Variable1 is not Variable2

Example

>>> a = 10
>>> b = 10
>>> a is not b
False
>>> a is not 10
False
>>> 10 is not 10
False