Keywords and Expressions

is — Object identity comparison

Compare whether two operands designate the same object. Identity is independent of value equality and cannot be overloaded using __eq__. Use is None for the None singleton; do not use is to compare numeric or string values because reuse of immutable objects may depend on the implementation. is not is the negated identity comparison, not a call to a user-defined equality method.

Formal Syntax & Structure

python syntaxpython
left is rightleft is not right

Parameters & Attributes

NameTypeDescription
leftobjectFirst object.
rightobjectSecond object.

Return Value

bool

True only for identical operands; is not gives the inverse.

Working Example

Example Snippetpython
first = [1, 2]alias = firstsecond = [1, 2]print(first is alias)print(first is second)print(first == second)print(None is None)
Python Reference