Quantcast
Channel: identifying objects, why does the returned value from id(...) change? - Stack Overflow
Browsing all 9 articles
Browse latest View live

Answer by A.Ajorian for identifying objects, why does the returned value from...

The thing is that, each object(value) has a unique id in Python, e.g objects 'hello' and 'hi' have their own ids or 10 and 11 have 2 other different ids. The other thing is that each variable is just a...

View Article



Answer by Ning Sun for identifying objects, why does the returned value from...

This is why 2**8 is 2**8 == True, and 2**9 is 2**9 == False.Values between -5 and 256 are preallocated.

View Article

Answer by David Z for identifying objects, why does the returned value from...

j's id changes because the object named by j changes. First you initialize j to 10, so when you call id(j) you get the id of 10. Then you set j to 11, so after that when you call id(j) you get the id...

View Article

Answer by Tim McNamara for identifying objects, why does the returned value...

The same id for different variables is a product of how Python creates variables. id is a hash of the the location of an object in memory. Python variables are references to an object, not new objects....

View Article

Answer by John Kugelman for identifying objects, why does the returned value...

Because integers are immutable, each integer value is a distinct object with a unique id. The integer 10 has a different id from 11. Doing j=j+1 doesn't change the value of an existing integer object,...

View Article


Answer by Srinivas Reddy Thatiparthy for identifying objects, why does the...

Python caches immutable objects(read integers and tuples..) - which is why they are immutableand saves memory if u reference the same immutable in manyplaces. So small integers, empty tuples and such...

View Article

Answer by Matt Joiner for identifying objects, why does the returned value...

In CPython, id is generally derived from the Py_Object's pointer value, that is its location in memory.

View Article

Answer by Anthony DiSanti for identifying objects, why does the returned...

These are primitive types, so I'm guessing each value gets its own ID. Try creating a true object and I think you'll see the functionality you expect.If you need an id for a primitive, you could create...

View Article


identifying objects, why does the returned value from id(...) change?

id(object)This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. Can you explain this output? Why does j's id change?>>> i=10...

View Article

Browsing all 9 articles
Browse latest View live




Latest Images