0

Suppose I have the following code in Python

a = 3
b = 3
if(id(a) == id(b)):
    print("Yes")

I am familiar with C, so I expected no output but the output was Yes. So I found the description of the function id using help(id) and it showed

Return the identity of an object. This is guaranteed to be unique among simultaneously existing objects. (CPython uses the object's memory address.)

Initially, I thought that it is returning memory locations. But now I am confused about what exactly is the identity that id is returning? Definitely, it is not returning the address of the memory location.

Infinity_hunter
  • 137
  • 1
  • 6
  • 2
    What you are seeing is a result of the small integer cache, a CPython optimisation. For most cases it is the memory location. – Selcuk Aug 26 '21 at 07:23

0 Answers0