== — 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
left == rightParameters & Attributes
| Name | Type | Description |
|---|---|---|
| left | object | First operand; its type participates in operation selection. |
| right | object | Second operand; supported values depend on the operand types. |
Return Value
Boolean for ordinary built-in comparisons; custom rich comparison methods can return other values.
Working Example
a=[1,2]b=[1,2]print(a==b, a is b)print(1==1.0)print(float("nan")==float("nan"))