is

KeywordPython 2.0+Beginner

Identity operator; tests whether two variables reference the same object

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

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}")

'is' tests identity (same object in memory), not equality. Always use 'is' for None, True, and False comparisons.

Try in Playground

Tags

languagesyntaxcoreidentityoperator