Operators

== — Value equality

Built-in numeric values can compare equal across types (for example 1 and 1.0). Distinct objects can be equal; lists compare element values and dictionaries compare key-value associations. NaN is not equal to itself. Equal hashable objects must have equal hashes. If both comparison implementations decline with NotImplemented, equality falls back to identity. Rich comparisons share precedence and support chaining: the middle operand is evaluated once, and later operands are skipped when a preceding comparison is falsy. Custom __eq__ results need not be bool. Custom dispatch uses __eq__ and the counterpart __eq__ on the other operand; a right-hand subclass may have priority.

Formal Syntax & Structure

python syntaxpython
left == right

Parameters & Attributes

NameTypeDescription
leftobjectFirst operand; its type participates in operation selection.
rightobjectSecond operand; supported values depend on the operand types.

Return Value

bool or custom result

Boolean for ordinary built-in comparisons; custom rich comparison methods can return other values.

Working Example

Example Snippetpython
a=[1,2]b=[1,2]print(a==b, a is b)print(1==1.0)print(float("nan")==float("nan"))
Python Reference