all Python 3astterm
ast.NotIn
operators
The not in membership operator in the ops list of a Compare node.
Syntax
ast.NotIn()
Although it is written as two words, it is one operator: a not in b gives a Compare with a single NotIn, with no UnaryOp or Not. Likewise is not is IsNot. Code that hunts for negation via ast.Not misses not in, whereas not a in b, with the same meaning, does produce UnaryOp(Not, Compare(In)).
Examples
import ast
n = ast.parse('x not in seen', mode='eval').body
print(type(n).__name__, [type(o).__name__ for o in n.ops]) # → Compare ['NotIn']
print(any(isinstance(m, ast.Not) for m in ast.walk(n))) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy