Reference Equality in Python

By Hemanta Sundaray on 2021-08-24

We can test whether two references refer to the exact same object using the is operator.

numbers = [12, 24, 36]

integers = [12, 24, 36]

print(numbers is integers)
# False

digits = numbers

print(digits is numbers)
# True

Even though numbers and integers contain the same values, they refer to two different objects in memory.

Join the Newsletter