Python Glossary Русский

all Python 3operatorfunction

operator.is_not

identity and logic

Negated identity test: a is not b.

Syntax

operator.is_not(a, b)

As a predicate it pairs well with functools.partial: filter(partial(operator.is_not, None), xs) drops None but keeps 0, empty strings and False — unlike filter(None, xs), which discards everything falsy. Since Python 3.14 operator.is_not_none does this out of the box.

Examples

import operator
print(operator.is_not([], []))   # → True
a = [1, 2]
print(operator.is_not(a, a))   # → False
print(operator.is_not(a, a[:]))   # → True
print(operator.is_not(None, None))   # → False
print(operator.is_not(a, [1, 2]), a != [1, 2])   # → True False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy