all Python 3operatorfunction
operator.is_
identity and logic
Identity test: a is b (the very same object in memory).
Syntax
operator.is_(a, b)
It compares objects, not values, so it suits None, sentinel singletons and checks like "is this the same list, not a copy". For numbers and strings the result depends on interpreter caching: is_(256, 256) is usually true, but not for large numbers or built-up strings. Compare values with eq.
Examples
import operator
x = []
print(operator.is_(x, x)) # → True
y = []
print(operator.is_(x, y)) # → False
print(operator.eq(x, y)) # → True
values = [None, 0, None]
print([operator.is_(v, None) for v in values]) # → [True, False, True]
print(operator.is_(True, 1)) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy