-1

From what I understand, the == operator checks if two variables are equal, while the is operator checks if two variables have the same identity/ reference the same object. So why is print(id(a) is id(b)) False ? Don't the two variables reference the same integer?

a = 1000000000
b = 1000000000

print(id(a))           #182798416
print(id(b))           #182798416
print(id(a) is id(b))  #False
print(id(a) == id(b))  #True
print(182798416 is 182798416) #True
MrSoLoDoLo
  • 365
  • 2
  • 18

1 Answers1

0

The id function returns a new integer object, each time, so the integer objects are not the same.

Daniel
  • 42,087
  • 4
  • 55
  • 81