all Python 3operatorfunction
operator.eq
comparison
Returns a == b (the function form of `==`).
Syntax
operator.eq(a, b)
It calls the left operand's __eq__ and falls back to the right one's if the left cannot compare, which is why eq(1, 1.0) is true. The result need not be a bool: a NumPy array returns an array of element-wise comparisons. NaN is not equal even to itself — eq(nan, nan) is False. With functools.partial it becomes a predicate: filter(partial(operator.eq, 0), xs) keeps the zeros.
Examples
import operator
print(operator.eq(1, 1)) # → True
print(operator.eq(1, 1.0)) # → True
print(operator.eq([1, 2], (1, 2))) # → False
print(list(map(operator.eq, [1, 2, 3], [1, 5, 3]))) # → [True, False, True]
print(operator.eq(float('nan'), float('nan'))) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy