0

id() function returns the identity of the object. This is an integer that is unique for the given object and remains constant during its lifetime.

And my experiment on 'id' function are below, I found something funny, as you can see below.

look at the output of id(x), when x is no more than 256, addresses are continuous, but when x be 257, it goes to another place.

So my question is why is 256? How do the designer of the language think about??

94256245865792
>>> id(2)
94256245865824
>>> id(2)-id(1)
32
>>> 
>>> id(256)
94256245873952
>>> id(257)
140417068686800
>>> (id(256)-id(1))/255
32.0```
  • Beyond small integers, you'll also find that the empty tuple `()` is always the same object and string literals having the same value are often reused as well. `a = 'abracatadra'; b = 'abracadabra'; id(a) == id(b)` – kindall Dec 22 '21 at 15:50

0 Answers0