Identity Operators
Last updated
Last updated
Python language offers some special types of operators like the identity operator or the membership operator. They are described below with examples.
is and is not are the identity operators in Python. They are used to check if two values (or variables) are located on the same part of the memory. Two variables that are equal does not imply that they are identical.
Operator | Meaning | Example |
---|---|---|
Output
Here, we see that x1
and y1
are integers of the same values, so they are equal as well as identical. Same is the case with x2
and y2
(strings).
But x3
and y3
are lists. They are equal but not identical. It is because the interpreter locates them separately in memory although they are equal.
is
True if the operands are identical (refer to the same object)
x is True
is not
True if the operands are not identical (do not refer to the same object)
x is