2 ms·
right, python caches ints from -5 to 256 as singletons, so id(x) for those numbers is constant. whereas each time you run id() on a number outside that range y
by cmcconomy 4y ago
right, python caches ints from -5 to 256 as singletons, so id(x) for those numbers is constant.
whereas each time you run id() on a number outside that range you will get a different id as a new object is instantiated
- kevincox 4y agoI don't think this is related. `set()` uses `hash(x)` it doesn't care what `id(x)` is. The example I provided works equally well with small numbers and large numbers.