is — Easy Examples
Identity operator; tests whether two variables reference the same object
Identity comparison
Using 'is' to check if two variables point to the same object.
python
# is checks identity (same object in memory) a = [1, 2, 3] b = a c = [1, 2, 3] print(f"a is b: {a is b}") # Same object print(f"a is c: {a is c}") # Different object, same value print(f"a == c: {a == c}") # Same value # Always use 'is' for None x = None print(f"x is None: {x is None}") print(f"x is not None: {x is not None}")
Expected Output
a is b: True a is c: False a == c: True x is None: True x is not None: False
'is' tests identity (same object in memory), not equality. Always use 'is' for None, True, and False comparisons.
Want to try these examples interactively?
Open Easy Playground