Python 3.14+operatorfunction
operator.is_none
identity and logic
Returns a is None — the identity test against None in functional form. Added in Python 3.14.
Syntax
operator.is_none(a)
It is handy as a predicate where a function is required: itertools.filterfalse(operator.is_none, xs) or any(map(operator.is_none, row)) — "are there gaps". It compares by identity, so 0, the empty string and False are not None. Before 3.14 partial(operator.is_, None) does the same.
Examples
import operator
is_none = getattr(operator, 'is_none', lambda a: a is None) # 3.14+ или аналог
print(is_none(None)) # → True
print(is_none(0)) # → False
print([is_none(x) for x in (1, None, '')]) # → [False, True, False]
print(list(filter(is_none, [1, None, 2, None]))) # → [None, None]
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy