Identity Operators
is and is not check whether two names refer to the very same object.
Easy
a = [1, 2]; b = [1, 2]
a == b # True — equal values
a is b # False — different objects
x is None # the correct way to test for None
Never use is to compare numbers or strings — small values may be cached and give misleading results.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.