Python 3.14+operatorfunction
operator.is_not_none
identity and logic
Returns a is not None — functional form of the "value is set" check; handy as a predicate for filter(). Added in Python 3.14.
Syntax
operator.is_not_none(a)
Unlike filter(None, xs), filter(operator.is_not_none, xs) keeps 0, empty strings and False — it drops None only. That is a common mistake when cleaning data where zero is a legitimate value. Before 3.14 partial(operator.is_not, None) gives the same predicate.
Examples
import operator
f = getattr(operator, 'is_not_none', lambda a: a is not None) # 3.14+ или аналог
print(f(None)) # → False
print(f(0)) # → True
print(list(filter(f, [1, None, 2, None]))) # → [1, 2]
print([f(x) for x in ('', None, 0)]) # → [True, False, True]
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy