Back
+10 XP
Concept

Identity vs Equality: `is` vs `==`

`==` checks if two values look identical. `is` checks if they share the exact same memory address in RAM.

python
x = [1, 2, 3]
y = [1, 2, 3]
print(x == y)  # True (same values)
print(x is y)  # False (two different objects in RAM)

# 54. Identity vs Equality: `is` vs `==` `==` checks if two values look identical. `is` checks if they share the exact same memory address in RAM: ```python x = [1, 2, 3] y = [1, 2, 3] print(x == y) # True (same values) print(x is y) # False (two different objects in RAM) ``` Industry rule: Use `is` exclusively for singletons like `None` (`if val is None:`), and `==` for comparing actual values.

Checkpoint

Why does `[42] is [42]` return `False`?

Practice

Check if variable `data` is `None` using the `is` operator, and print "Empty" if True.

Terminal
01
Tap code blocks below to assemble
Available Blocks