Definition
Equality in Python refers to whether two variables contain equivalent values, evaluated using the == operator.
Why It Matters
It is the standard comparison method used to check if the data values of two objects match.
Core Concepts
a = [1, 2, 3]
b = [1, 2, 3]
# Equality (Value comparison)
print(a == b) # True
# Identity (Memory address comparison)
print(a is b) # False (different objects in memory)
- Equality (
==): Asks, “Are the values inside these objects the same?” (e.g.,[1, 2] == [1, 2]isTrue). id()Function: Returns the unique integer identifier (memory address) of an object. Ifid(a) == id(b), thena is b.