Python Glossary Русский

all Python 3operatorfunction

operator.ne

comparison

Return a != b — the functional form of the "not equal" operator.

Syntax

operator.ne(a, b)

If a class defines __eq__ but not __ne__, Python derives ne as the negation of eq — you do not need both methods. For NaN ne(nan, nan) is true, the classic way to detect NaN without importing math. To drop a specific value from a sequence: filter(partial(operator.ne, None), xs).

Examples

import operator
print(operator.ne(1, 2))   # → True
print(operator.ne('a', 'a'))   # → False
print(operator.ne(1, 1.0))   # → False
values = [3, 0, 3, 7]
print([v for v in values if operator.ne(v, 3)])   # → [0, 7]
print(operator.ne(float('nan'), float('nan')))   # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy